OAuth2Helper class

Helper class for simplifying OAuth2 authorization process.

Tokens are stored in a secure storage. The helper performs automatic token refreshing upon access token expiration. Moreover it provides methods to perform http post/get calls with automatic Access Token injection in the requests header

Constructors

OAuth2Helper(OAuth2Client client, {int grantType = authorizationCode, required String clientId, String? clientSecret, List<String>? scopes, bool enablePKCE = true, bool enableState = true, dynamic tokenStorage, Function? afterAuthorizationCodeCb, Map<String, dynamic>? authCodeParams, Map<String, dynamic>? accessTokenParams, Map<String, String>? accessTokenHeaders, BaseWebAuth? webAuthClient, Map<String, dynamic>? webAuthOpts})

Properties

accessTokenHeaders Map<String, String>?
getter/setter pair
accessTokenParams Map<String, dynamic>?
getter/setter pair
afterAuthorizationCodeCb Function?
getter/setter pair
authCodeParams Map<String, dynamic>?
getter/setter pair
client OAuth2Client
final
clientId String
getter/setter pair
clientSecret String?
getter/setter pair
enablePKCE bool
getter/setter pair
enableState bool
getter/setter pair
grantType int
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scopes List<String>?
getter/setter pair
tokenStorage TokenStorage
getter/setter pair
webAuthClient BaseWebAuth?
getter/setter pair
webAuthOpts Map<String, dynamic>?
getter/setter pair

Methods

delete(String url, {Map<String, String>? headers, Client? httpClient}) Future<Response>
Performs a DELETE request to the specified url, adding the authorization token.
disconnect({dynamic httpClient}) Future<OAuth2Response>
Revokes the previously fetched token
fetchToken() Future<AccessTokenResponse>
Fetches a new token and saves it in the storage
get(String url, {Map<String, String>? headers, Client? httpClient}) Future<Response>
Performs a GET request to the specified url, adding the authorization token.
getToken() Future<AccessTokenResponse?>
Returns a previously required token, if any, or requires a new one.
getTokenFromStorage() Future<AccessTokenResponse?>
Returns the previously stored Access Token from the storage, if any
Performs a HEAD request to the specified url, adding the authorization token.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
patch(String url, {Map<String, String>? headers, dynamic body, Client? httpClient}) Future<Response>
Performs a PATCH request to the specified url, adding the authorization token.
post(String url, {Map<String, String>? headers, dynamic body, Client? httpClient}) Future<Response>
Performs a POST request to the specified url, adding the authorization token.
put(String url, {Map<String, String>? headers, dynamic body, Client? httpClient}) Future<Response>
Performs a PUT request to the specified url, adding the authorization token.
refreshToken(AccessTokenResponse curTknResp) Future<AccessTokenResponse>
Performs a refresh_token request using the refreshToken.
removeAllTokens() Future
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Constants

authorizationCode → const int
clientCredentials → const int
implicitGrant → const int