Class DeviceOAuth
Implementation of device based OAuth2 flow.
Inherited Members
Namespace: DeviceOAuth2
Assembly: DeviceOAuth2.dll
Syntax
public sealed class DeviceOAuth : IDeviceOAuth2, IDeviceOAuth2Stepwise, IDeviceOAuthInfo
Constructors
| Improve this Doc View SourceDeviceOAuth(EndPointInfo, String, String)
ctor
Declaration
public DeviceOAuth(EndPointInfo authEndPoint, string scope, string clientId)
Parameters
| Type | Name | Description |
|---|---|---|
| EndPointInfo | authEndPoint | |
| String | scope | |
| String | clientId |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | scope or clientId are null or empty |
| ArgumentNullException | authEndPoint is null |
DeviceOAuth(EndPointInfo, String, String, String)
ctor
Declaration
public DeviceOAuth(EndPointInfo authEndPoint, string scope, string clientId, string clientSecret)
Parameters
| Type | Name | Description |
|---|---|---|
| EndPointInfo | authEndPoint | |
| String | scope | |
| String | clientId | |
| String | clientSecret | Allowed to be null or empty |
Exceptions
| Type | Condition |
|---|---|
| InvalidOperationException | scope or clientId are null or empty |
| ArgumentNullException | authEndPoint is null |
Properties
| Improve this Doc View SourceClientId
The ClientId of the app requesting authorization.
Declaration
public string ClientId { get; }
Property Value
| Type | Description |
|---|---|
| String |
EndPoint
The endpoint of the OAuth2 interface
Declaration
public EndPointInfo EndPoint { get; }
Property Value
| Type | Description |
|---|---|
| EndPointInfo |
Scope
The scope(s) being authorized.
Declaration
public string Scope { get; }
Property Value
| Type | Description |
|---|---|
| String |
Methods
| Improve this Doc View SourceAuthorize(TokenInfo)
Starts the authorization flow. If a non-null auth Token is passed, and it has a refresh token, the access token will be generated by refreshing. Otherwise if token is null or has no RefreshToken, a new authorization flow will be started.
Declaration
public Task<TokenInfo> Authorize(TokenInfo token)
Parameters
| Type | Name | Description |
|---|---|---|
| TokenInfo | token | An existing auth token that can be checked for needing to be refreshed. Pass null if the app has never been authorized. |
Returns
| Type | Description |
|---|---|
| Task<TokenInfo> | An auth token. If the token parameter is still valid it will be returned |
Exceptions
| Type | Condition |
|---|---|
| UnauthorizedAccessException | Thrown when the user denies access |
| TimeoutException | Thrown when the user does not respond in the time alotted by the service |
| DynamicRestProxy.PortableHttpClient.DynamicRestClientResponseException | When there is an http failure |
Authorize(TokenInfo, CancellationToken)
Starts the authorization flow. If a non-null auth Token is passed, and it has a refresh token, the access token will be generated by refreshing. Otherwise if token is null or has no RefreshToken, a new authorization flow will be started.
Declaration
public Task<TokenInfo> Authorize(TokenInfo token, CancellationToken cancelToken)
Parameters
| Type | Name | Description |
|---|---|---|
| TokenInfo | token | An existing auth token that can be checked for needing to be refreshed. Pass null if the app has never been authorized. |
| CancellationToken | cancelToken | Cancellation token |
Returns
| Type | Description |
|---|---|
| Task<TokenInfo> | An auth token. If the token parameter is still valid it will be returned |
Exceptions
| Type | Condition |
|---|---|
| UnauthorizedAccessException | Thrown when the user denies access |
| TimeoutException | Thrown when the user does not respond in the time alotted by the service |
| DynamicRestProxy.PortableHttpClient.DynamicRestClientResponseException | When there is an http failure |
CheckToken(TokenInfo)
Checks the validity of an auth token against the auth endpoint. It does this by making a get request to the token's ProfileUri. This is useful for ensuring that the user hasn't revoked authorization for a stored token and that it hasn't expired.
Declaration
public Task<bool> CheckToken(TokenInfo token)
Parameters
| Type | Name | Description |
|---|---|---|
| TokenInfo | token | The auth token to check |
Returns
| Type | Description |
|---|---|
| Task<Boolean> | True if the auth token is stil valid |
CheckToken(TokenInfo, CancellationToken)
Checks the validity of a token against the auth endpoint. It does this by making a get request to the token's ProfileUri. This is useful for ensuring that the user hasn't revoked authorization for a stored token and that it hasn't expired.
Declaration
public Task<bool> CheckToken(TokenInfo token, CancellationToken cancelToken)
Parameters
| Type | Name | Description |
|---|---|---|
| TokenInfo | token | The auth token to check |
| CancellationToken | cancelToken | A cancellation token |
Returns
| Type | Description |
|---|---|
| Task<Boolean> | True if the auth token is stil valid |
GetProfile(TokenInfo)
Returns the user's endpoint profile using ProfileUri.
Declaration
public Task<dynamic> GetProfile(TokenInfo token)
Parameters
| Type | Name | Description |
|---|---|---|
| TokenInfo | token | The auth token |
Returns
| Type | Description |
|---|---|
| Task<Object> | User's profile |
Exceptions
| Type | Condition |
|---|---|
| DynamicRestProxy.PortableHttpClient.DynamicRestClientResponseException | When there is an http failure |
GetProfile(TokenInfo, CancellationToken)
Returns the user's endpoint profile using ProfileUri.
Declaration
public Task<dynamic> GetProfile(TokenInfo token, CancellationToken cancelToken)
Parameters
| Type | Name | Description |
|---|---|---|
| TokenInfo | token | The auth token |
| CancellationToken | cancelToken | A cancellation token |
Returns
| Type | Description |
|---|---|
| Task<Object> | User's profile |
Exceptions
| Type | Condition |
|---|---|
| DynamicRestProxy.PortableHttpClient.DynamicRestClientResponseException | When there is an http failure |
Events
| Improve this Doc View SourcePromptUser
Event raised when the auth confirmation url and code are known. Display these to the user and tell them to enter the code at the referenced web page.
Declaration
public event EventHandler<AuthInfo> PromptUser
Event Type
| Type | Description |
|---|---|
| EventHandler<AuthInfo> |
WaitingForConfirmation
Status event raised each time confirmation is checked for. The int argument is number of seconds remaining before the auth flow times out.
Declaration
public event EventHandler<int> WaitingForConfirmation
Event Type
| Type | Description |
|---|---|
| EventHandler<Int32> |
Explicit Interface Implementations
| Improve this Doc View SourceIDeviceOAuth2Stepwise.RefreshAccessToken(TokenInfo)
Refreshes the access token
Declaration
Task<TokenInfo> IDeviceOAuth2Stepwise.RefreshAccessToken(TokenInfo token)
Parameters
| Type | Name | Description |
|---|---|---|
| TokenInfo | token | The token to refresh |
Returns
| Type | Description |
|---|---|
| Task<TokenInfo> | A refreshed auth token |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | TokenInfo is null |
| InvalidOperationException | The TokenInfo is not refreshable |
| DynamicRestProxy.PortableHttpClient.DynamicRestClientResponseException | When there is an http failure |
IDeviceOAuth2Stepwise.RefreshAccessToken(TokenInfo, CancellationToken)
Refreshes the access token
Declaration
Task<TokenInfo> IDeviceOAuth2Stepwise.RefreshAccessToken(TokenInfo token, CancellationToken cancelToken)
Parameters
| Type | Name | Description |
|---|---|---|
| TokenInfo | token | The token to refresh |
| CancellationToken | cancelToken | A cancellation token |
Returns
| Type | Description |
|---|---|
| Task<TokenInfo> | A refreshed auth token |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | TokenInfo is null |
| InvalidOperationException | The TokenInfo is not refreshable |
| DynamicRestProxy.PortableHttpClient.DynamicRestClientResponseException | When there is an http failure |
IDeviceOAuth2Stepwise.StartAuthorization()
Starts a new authorization flow
Declaration
Task<AuthInfo> IDeviceOAuth2Stepwise.StartAuthorization()
Returns
| Type | Description |
|---|---|
| Task<AuthInfo> | Auth information to be displayed to the user |
Exceptions
| Type | Condition |
|---|---|
| DynamicRestProxy.PortableHttpClient.DynamicRestClientResponseException | When there is an http failure |
IDeviceOAuth2Stepwise.StartAuthorization(CancellationToken)
Starts a new authorization flow
Declaration
Task<AuthInfo> IDeviceOAuth2Stepwise.StartAuthorization(CancellationToken cancelToken)
Parameters
| Type | Name | Description |
|---|---|---|
| CancellationToken | cancelToken |
Returns
| Type | Description |
|---|---|
| Task<AuthInfo> | Auth information to be displayed to the user |
Exceptions
| Type | Condition |
|---|---|
| DynamicRestProxy.PortableHttpClient.DynamicRestClientResponseException | When there is an http failure |
IDeviceOAuth2Stepwise.WaitForUserConsent(AuthInfo)
Polls the service endpoint until the user gives authorization or the Expiration passes
Declaration
Task<TokenInfo> IDeviceOAuth2Stepwise.WaitForUserConsent(AuthInfo info)
Parameters
| Type | Name | Description |
|---|---|---|
| AuthInfo | info | The end point to authorize |
Returns
| Type | Description |
|---|---|
| Task<TokenInfo> | An auth token |
Exceptions
| Type | Condition |
|---|---|
| UnauthorizedAccessException | Thrown when the user denies access |
| TimeoutException | Thrown when the user does not respond in the time alotted by the service |
| DynamicRestProxy.PortableHttpClient.DynamicRestClientResponseException | When there is an http failure |
IDeviceOAuth2Stepwise.WaitForUserConsent(AuthInfo, CancellationToken)
Polls the service endpoint until the user gives authorization or the Expiration passes
Declaration
Task<TokenInfo> IDeviceOAuth2Stepwise.WaitForUserConsent(AuthInfo info, CancellationToken cancelToken)
Parameters
| Type | Name | Description |
|---|---|---|
| AuthInfo | info | The end point to authorize |
| CancellationToken | cancelToken | A cancellation token |
Returns
| Type | Description |
|---|---|
| Task<TokenInfo> | An auth token |
Exceptions
| Type | Condition |
|---|---|
| UnauthorizedAccessException | Thrown when the user denies access |
| TimeoutException | Thrown when the user does not respond in the time alotted by the service |
| DynamicRestProxy.PortableHttpClient.DynamicRestClientResponseException | When there is an http failure |