v0.0.3flutter_dauth
एक फ्लटर पैकेज जो क्लाइंट-एप्प को एक संसाधन के एक्सेस और संशोधन की अनुमति देता है जिसका मालिक संसाधन मालिक (उपयोगकर्ता) है और जो DAuth सर्वर पर स्थित है।
DAuth (NITT छात्रों के लिए आधारित OAuth2 आधारित SSO (एकल साइन ऑन)) प्राप्ति सेवा के माध्यम से संसाधन-मालिक/उपयोगकर्ता के प्रतिनिधित्व में प्रमाणीकरण के लिए एक Flutter पैकेज।
{"sdk":"flutter"}^0.13.4^0.2.1^3.0.1{"sdk":"flutter"}^1.0.0यह अंग्रेज़ी मूल स्नैपशॉट है। नवीनतम सामग्री GitHub पर देखें।
A flutter package for authentication with DAuth(an OAuth2 based SSO (Single Sign On) for NITT students) authorisations service on behalf of the resource-owner/user. DAuth lets the application developers securely get access to users’ data without users having to share their passwords.
DAuth allows a Client-App (the program using this library) to access and manipulate a resource that's owned by a resource owner (the end user) and lives on a remote server. The Client-App directs the resource owner to dauth authorization server, where the resource owner tells the authorization server to give the Client-App an access token. This token serves as proof that the client has permission to access resources on behalf of the resource owner.
Note: OAuth2 provides several different methods for the client to obtain authorization.But, currently This package only supports Authorisation Code Grant
AuthorisationCodeGrant
fetchToken(authorizationRequest), which automates the following workflow:
authorizationUrl using the provided authorizationRequest in the parameter.authorizationUrl and Listens to the NavigationRequests.redirect_uri and code is fetched by listening to the NavigationRequest.tokenResponse is fetched the user can send a post request using fetchResources(token) and get the protectedResources based on the Scope mentioned.| DataTypes | Parameters | Description |
|---|---|---|
| ResourceResponse | String? tokenType, String? accessToken, String? state, int? expiresIn,String? idToken,String? status,ErrorResponse? errorResponse | Response-body returned from fetchResources() request |
| TokenResponse | String? email,String? id,String? name,String? phoneNumber,String? gender,DateTime? createdAt,DateTime? updatedAt, | Response-body returned from fetchToken() request |
| Scope | bool isOpenId, bool isEmail, bool isProfile, bool isUser | Consists of 4 boolean parameters to enable SCOPE of Resource Access |
| TokenRequest | String? clientId,String? codeVerifier,String codeChallengeMethod,String? redirectUri,String? responseType,String? grantType,String? state,String? scope,String? nonce | Request-Parameter for fetchToken() |
| Methods | Parameters |
|---|---|
TokenResponse fetchToken() |
TokenRequest request |
ResourceResponse fetchResource() |
String access_token |
Widget DauthButton() |
Function OnPressed: (TokenResponse res){} |
To use this package:
flutter pub get flutter_dauth
ORdependencies:
flutter:
sdk: flutter
flutter_dauth:
Following is an example of Authorization Grant Code using this package.
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => const MaterialApp(
debugShowCheckedModeBanner: false,
home: HomePage(),
);
}
class HomePage extends StatefulWidget {
const HomePage({Key? key}) : super(key: key);
@override
State<StatefulWidget> createState() => HomeState();
}
class HomeState extends State<HomePage> {
//A string object used in Text() widget as data.
String _exampleText = 'Flutter Application';
//Create a TokenRequest Object
final dauth.TokenRequest _request = TokenRequest(
//Your Client-Id provided by Dauth Server at the time of registration.
clientId: 'YOUR CLIENT ID',
//redirectUri provided by You to Dauth Server at the time of registration.
redirectUri: 'YOUR REDIRECT URI',
//A String which will retured with access_token for token verification in client side.
state: 'STATE',
//setting isUser to true to retrive UserDetails in ResourceResponse from Dauth server.
scope: const dauth.Scope(isUser: true),
//codeChallengeMethod Should be specified as `plain` or `S256` based on thier requirement.
codeChallengeMethod: 'S256');
@override
Widget build(BuildContext context) => SafeArea(
child: Scaffold(
body: Container(
color: Colors.blueGrey,
child: Stack(
children: [
Center(
child: Text(
_exampleText,
style: const TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
)),
Positioned(
left: 50,
right: 50,
bottom: 10,
//DAuth button returns TokenResponse and ResponseMessage when pressed.
child: dauth.DauthButton(
request: _request,
onPressed:
(dauth.TokenResponse res) {
//changes the exampleText as Token_TYPE: <YOUR_TOKEN> from the previous string if the response is success'
setState(() {
_exampleText = 'Token_TYPE: ' +
(res)
.tokenType
.toString();
});
}))
],
),
)));
}
This package wouldn't be possible without the following: