hamuga_id_sdk 0.0.7
hamuga_id_sdk: ^0.0.7 copied to clipboard
A Flutter package that provides a HamugaIdButton widget for easy integration with Hamuga ID authentication.
Hamuga ID SDK #
A Flutter package that provides a HamugaIdButton widget for easy integration with Hamuga ID authentication.
Features #
- A customizable
HamugaIdButtonwidget. - Support for different button sizes (
sm,md,lg,xl,xxl). - Multiple button variants (
primary,secondaryGray,secondaryColor,tertiaryGray,tertiaryColor,linkGray,linkColor). - Handles the Hamuga ID OAuth 2.0 authentication flow.
- Support for
openid,email,phone, anddanscopes.
Getting started #
-
Add this to your package's
pubspec.yamlfile:dependencies: hamuga_id_sdk: ^0.0.7 # Replace with the latest version -
Install it:
flutter pub get -
Import the package:
import 'package:hamuga_id_sdk/hamuga_id_sdk.dart';
Usage #
Here is a basic example of how to use the HamugaIdButton:
import 'package:flutter/material.dart';
import 'package:hamuga_id_sdk/hamuga_id_sdk.dart';
class LoginScreen extends StatelessWidget {
const LoginScreen({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
HamugaIdButton(
clientId: 'YOUR_CLIENT_ID', // Replace with your client ID
redirectUri: 'YOUR_REDIRECT_URI', // Replace with your redirect URI
scope: const [HamugaIdScope.openid, HamugaIdScope.email],
onPressed: () {
// This callback is executed after the URL is launched.
print('Authentication process started...');
},
),
const SizedBox(height: 16),
ElevatedButton(
onPressed: () {
HamugaId.open(
clientId: 'YOUR_CLIENT_ID',
redirectUri: 'YOUR_REDIRECT_URI',
scope: const [HamugaIdScope.openid, HamugaIdScope.email],
);
},
child: const Text('Custom Open Function'),
),
],
),
),
),
);
}
}
HamugaId.open #
You can also use the HamugaId.open static method directly if you want to trigger the authentication flow from your own custom widget or logic.
HamugaId.open(
clientId: 'YOUR_CLIENT_ID',
redirectUri: 'YOUR_REDIRECT_URI',
scope: const [HamugaIdScope.openid, HamugaIdScope.email],
// Optional parameters
state: '123',
baseUrl: 'https://hamuga.id/oauth/authorize',
responseType: 'code',
username: HamugaIdUsername.email,
);
HamugaId.listenDeepLink #
To handle the authentication response (callback), you must listen for incoming deep links.
HamugaId.listenDeepLink((response) {
if (response.isSuccess) {
print('Auth Code: ${response.code}');
print('State: ${response.state}');
// Proceed to exchange the code for an access token on your backend
} else {
print('Auth Error: ${response.error}');
print('Description: ${response.errorDescription}');
}
});
Deep Link Configuration #
To receive the callback in your app, you must configure URL schemes in your native projects.
Android
In android/app/src/main/AndroidManifest.xml, add an intent-filter to your .MainActivity:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<!-- Replace with your redirect URI details -->
<data android:scheme="my-app" android:host="callback" />
</intent-filter>
iOS
In ios/Runner/Info.plist, add your URL scheme:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>my-app</string>
</array>
</dict>
</array>
HamugaIdButton Properties #
| Parameter | Type | Description | Default |
|---|---|---|---|
onPressed |
VoidCallback? |
Callback function when the button is pressed. | null |
text |
String |
The text displayed on the button. | 'Хамуга ID-р нэвтрэх' |
leadingIcon |
Widget? |
A widget to display before the text. | SvgPicture of Hamuga logo |
trailingIcon |
Widget? |
A widget to display after the text. | null |
size |
HamugaButtonSize |
The size of the button. | HamugaButtonSize.md |
variant |
HamugaButtonVariant |
The visual style of the button. | HamugaButtonVariant.secondaryGray |
clientId |
String |
Required. Your application's client ID. | |
redirectUri |
String |
Required. The URI to redirect to after authentication. | |
state |
String? |
An opaque value used to maintain state between the request and the callback. | '123' |
baseUrl |
String? |
The base URL for the authentication endpoint. | 'https://hamuga.id/oauth/authorize' |
scope |
List<HamugaIdScope> |
Required. A list of scopes to request. | |
username |
HamugaIdUsername? |
Type to pass | |
responseType |
String? |
The type of response expected. | 'code' |
enabled |
bool |
Whether the button is enabled. | true |
Enums #
HamugaButtonSize
smmdlgxlxxl
HamugaButtonVariant
primarysecondaryGraysecondaryColortertiaryGraytertiaryColorlinkGraylinkColor
HamugaIdScope
openidemailphonedan
Additional information #
For more information, feel free to browse the source code. If you encounter any issues or have suggestions, please file an issue on the project's GitHub repository.