sayari_oauth_flutter_sdk 0.2.1
sayari_oauth_flutter_sdk: ^0.2.1 copied to clipboard
Reusable Sayari OAuth SDK for Flutter apps with PKCE, deep-link callbacks, and backend exchange helpers.
Sayari OAuth Flutter SDK #
Reusable Flutter helpers for integrating Sayari Account login into mobile and desktop apps.
Features #
- builds the Sayari authorize URL
- generates and manages PKCE values
- parses deep-link callbacks
- prepares the backend exchange payload
- launches the authorization flow
- supports optional
loginHintprefill
Install #
Add the package to your pubspec.yaml:
dependencies:
sayari_oauth_flutter_sdk:
path: ../sayari_oauth_flutter_sdk
Or depend on the published pub.dev version.
Quick Start #
import 'package:sayari_oauth_flutter_sdk/sayari_oauth_flutter_sdk.dart';
final config = SayariOAuthConfig(
appId: 'YOUR_APP_ID',
authorizeUrl: 'https://accounts.sayarisoftware.com/oauth/authorize',
tokenUrl: 'https://accounts-api.sayarisoftware.com/api/v1/oauth/token',
redirectUri: 'myapp://auth/callback',
providerOrigin: 'https://accounts.sayarisoftware.com',
backendBaseUrl: 'https://your-backend.example.com',
appName: 'My Flutter App',
);
final sdk = SayariOAuthFlutterSdk(config);
final pkce = sdk.createPkce();
await sdk.launchAuthorize(
pkce: pkce,
loginHint: 'name@example.com',
);
Typical Flow #
- Create a
SayariOAuthConfig. - Generate PKCE with
createPkce(). - Launch the Sayari authorization flow.
- Receive the deep-link callback.
- Validate the callback state.
- Send the authorization code to your backend.
- Exchange the code with Sayari on your backend.
Core API #
SayariOAuthConfig #
Defines the app registration and Sayari endpoints.
Required:
appIdauthorizeUrltokenUrlredirectUriproviderOrigin
Optional:
appNameappIconbackendBaseUrlscopeloginHint
SayariPkce #
Creates PKCE values for the authorization flow.
final pkce = SayariPkce.generate();
SayariOAuthTransaction #
Keeps one login attempt together and helps guard against replaying the same callback.
SayariOAuthClient #
Lower-level helpers for:
- building the authorize URI
- launching the flow
- parsing the callback
- building the backend exchange payload
- posting the exchange request
SayariOAuthFlutterSdk #
The main entrypoint for most Flutter apps.
Backend Exchange Payload #
The SDK builds a payload like this:
{
"grantType": "authorization_code",
"code": "authorization_code_from_deep_link",
"redirectUri": "myapp://auth/callback",
"appId": "YOUR_APP_ID",
"codeVerifier": "original_pkce_verifier",
"state": "original_state"
}
Your backend should exchange that code with Sayari and create the app session.
Notes #
- The user still signs in to Sayari Account.
loginHintis optional and only pre-fills the Sayari login identity.- The
redirectUriused at authorize time and exchange time must match exactly. - The same authorization code should only be exchanged once.
- The SDK is designed to work with your own backend session logic.
Example App #
This package includes a publishable example app under example/.
It demonstrates:
- loading the SDK config
- building and launching the Sayari authorize URL
- handling the deep-link callback
- exchanging the code with a backend
- displaying the returned session summary
Dependencies #
app_linkscryptohttpurl_launcher
Best For #
Use this package when you want to add Sayari OAuth to:
- Flutter mobile apps
- desktop apps
- internal tools
- reusable client libraries