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

outdated

Add and manage OAuth2 authentication for your Chopper client.

Add and manage OAuth2 authentication for your Chopper client

Features #

Offers a oauth_chopper client to help manage your OAuth2 authentication with Choppper. The oauth_chopper client uses oauth2 package from the dart team and combines this with Chopper. It offers a Chopper Authenticator and HeaderInterceptor to manage the OAuth2 authorizations.

By default it doesn't persist any credential information. It uses an in memory storage by default. This can be override by providing a custom storage implementation.

Currently it supports the following grants:

  • ✅ ResourceOwnerPasswordGrant
  • ✅ ClientCredentialsGrant
  • ❌ AuthorizationCodeGrant (TODO)

Usage #

Create a oauth_chopper client with the needed authorizationEndpoint, identifier and secret.
Add the oauth_chopper_authenticator + oauth_chopper_interceptor to your chopper client.
Request a OAuthGrant on the oauth_chopper client.

Example:

 /// Create OAuthChopper instance.  
 final oauthChopper = OAuthChopper(    authorizationEndpoint: authorizationEndpoint,   
    identifier: identifier,   
    secret: secret,  
 ); /// Add the oauth authenticator and interceptor to the chopper client. final chopperClient = ChopperClient(    
    baseUrl: 'https://example.com',   
    authenticator: oauthChopper.authenticator(),  
 interceptors: [ oauthChopper.interceptor, ], ); /// Request grant oauthChopper.requestGrant(    
   ResourceOwnerPasswordGrant(    
      username: 'username',    
      password: 'password',    
), ); 

If you want to persist the OAuth2 credential information you can provide a custom OAuthStorage implementation for example with flutter_secure_storage:

const _storageKey = 'storage_key';  
  
class OAuthCredentialsStorage implements OAuthStorage {    
  final FlutterSecureStorage _storage;    
    
 const OAuthCredentialsStorage(this._storage);    
    
  @override    
  FutureOr<void> clear() async {    
    await _storage.delete(key: _storageKey);    
  }    
    
  @override    
  FutureOr<String?> fetchCredentials() async {    
    final credentialsJson = await _storage.read(key: _storageKey);    
 return credentialsJson;    
  }    
    
  @override    
  FutureOr<void> saveCredentials(String? credentialsJson) async {    
    await _storage.write(key: _storageKey, value: credentialsJson);    
} }  

Additional information #

Feel free to give me any feedback to improve this package.

2
likes
0
points
84
downloads

Publisher

verified publisherdutchcodingcompany.com

Weekly Downloads

Add and manage OAuth2 authentication for your Chopper client.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

chopper, oauth2

More

Packages that depend on oauth_chopper