hamuga_id_sdk 0.0.6 copy "hamuga_id_sdk: ^0.0.6" to clipboard
hamuga_id_sdk: ^0.0.6 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 HamugaIdButton widget.
  • 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, and dan scopes.

Getting started #

  1. Add this to your package's pubspec.yaml file:

    dependencies:
      hamuga_id_sdk: ^0.0.1 # Replace with the latest version
    
  2. Install it:

    flutter pub get
    
  3. 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,
);

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

  • sm
  • md
  • lg
  • xl
  • xxl

HamugaButtonVariant

  • primary
  • secondaryGray
  • secondaryColor
  • tertiaryGray
  • tertiaryColor
  • linkGray
  • linkColor

HamugaIdScope

  • openid
  • email
  • phone
  • dan

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.

0
likes
0
points
33
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package that provides a HamugaIdButton widget for easy integration with Hamuga ID authentication.

Homepage

License

unknown (license)

Dependencies

flutter, flutter_svg, url_launcher

More

Packages that depend on hamuga_id_sdk