OAuth2PkceUtil class

Generic utility class for OAuth2 token exchange with optional PKCE support.

This class provides the core logic for exchanging an authorization code for an access token. It follows a generic pattern keeping the core logic reusable across different OAuth2 providers.

The OAuth2 flow involves:

  1. Client generates a code verifier and code challenge (if using PKCE)
  2. Client initiates authorization with the code challenge
  3. User authorizes the application
  4. Client receives an authorization code
  5. Client exchanges the code and code verifier for an access token

This utility handles step 5 (token exchange) on the server side.

Usage

Create a provider-specific configuration that implements OAuth2PkceServerConfig and pass it to the constructor:

final oauth2Util = OAuth2PkceUtil(config: myProviderConfig);

final accessToken = await oauth2Util.exchangeCodeForToken(
  code: authorizationCode,
  redirectUri: 'https://example.com/callback',
);

Constructors

OAuth2PkceUtil({required OAuth2PkceServerConfig config})
Creates a new OAuth2PkceUtil with the given configuration.

Properties

config OAuth2PkceServerConfig
The provider-specific configuration for OAuth2 PKCE.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

exchangeCodeForToken({required String code, String? codeVerifier, required String redirectUri, Client? httpClient}) Future<OAuth2PkceTokenResponse>
Exchanges an authorization code for an access token.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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