Class TokenHelper
Provides token management for authenticating with the Transit Azure Exchange API.
Inheritance
Namespace: Transit.Shared.Communication.Azure.Exchange
Assembly: Transit.Shared.dll
Syntax
public class TokenHelper
Remarks
This class supports two authentication flows:
- Interactive browser login: Used when no scope is provided. Opens a browser window for user authentication.
- Client credentials flow: Used when a scope is provided. Authenticates using client ID and secret from the discovery metadata.
The token is cached internally and automatically refreshed when it expires.
Constructors
TokenHelper()
Initializes a new instance of the TokenHelper class for interactive browser login.
Declaration
public TokenHelper()
TokenHelper(string)
Initializes a new instance of the TokenHelper class for client credentials authentication.
Declaration
public TokenHelper(string scope)
Parameters
| Type | Name | Description |
|---|---|---|
| string | scope | The scope value to use for authentication. |
Properties
Scope
Gets the scope value used for client credentials authentication.
Declaration
public string Scope { get; }
Property Value
| Type | Description |
|---|---|
| string | The scope string, or null if interactive browser login is used. |
Methods
GetValueAsync(CancellationToken)
Gets an access token for authenticating API requests.
Declaration
public Task<string> GetValueAsync(CancellationToken cancellationToken)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancellationToken | A token to cancel the operation. |
Returns
| Type | Description |
|---|---|
| Task<string> | The access token string. |
Remarks
If a valid cached token exists, it is returned immediately. Otherwise, a new token is obtained using either browser login or client credentials flow, depending on whether a scope was provided during construction.
Exceptions
| Type | Condition |
|---|---|
| Exception | Thrown when authentication fails. |