tiny_pkce 0.0.1 copy "tiny_pkce: ^0.0.1" to clipboard
tiny_pkce: ^0.0.1 copied to clipboard

PlatformiOSmacOS

A tiny PKCE implementation for Flutter

tiny_pkce #

A lightweight Flutter package for OAuth 2.0 PKCE authentication flow.

Features #

  • Implements OAuth 2.0 PKCE (Proof Key for Code Exchange) flow
  • Automatic token refresh handling
  • Secure token storage using flutter_secure_storage
  • Support for iOS, macOS and Web platforms
  • Built-in URI handling for OAuth redirects
  • Status updates via Stream and ChangeNotifier
  • Customizable scopes and endpoints

Getting Started #

Add the package to your pubspec.yaml:

Basic Setup #

  1. Initialize the AuthService with your OAuth configuration:
final auth = AuthService(
    discoveryUrl: 'https://your-auth-server/.well-known/openid-configuration',
    clientId: 'your_client_id',
    redirectUrl: 'your.app.scheme:/oauth/callback',
    scopes: ['openid', 'profile', 'email'],
    // Optional: For web platform
webRedirectUrl: "http://localhost:8080/login-callback",
);
  1. Initialize the service in your app's startup:
await auth.init();
  1. Handle the authentication flow in your UI:
// Login
auth.launchLogin();
// Logout
auth.logout();
// Listen to auth status changes
auth.addListener(() {
    switch (auth.status) {
        case AuthServiceStatus.loggedIn:
        // Handle logged in state
        break;
        case AuthServiceStatus.loggedOut:
        // Handle logged out state
        break;
        case AuthServiceStatus.loading:
        // Handle loading state
        break;
    }
});


// Access tokens and claims
final accessToken = await auth.accessToken;
final idToken = await auth.idToken;
final refreshToken = await auth.refreshToken;
final idClaims = await auth.idClaims;

Copyright 2024 @ElectricCookie

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

0
likes
120
points
79
downloads

Publisher

unverified uploader

Weekly Downloads

A tiny PKCE implementation for Flutter

Repository (GitHub)

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

app_links, crypto, flutter, flutter_secure_storage, flutter_web_plugins, http, json_annotation, plugin_platform_interface, tiny_pkce_launcher, url_launcher

More

Packages that depend on tiny_pkce