C# Class DotNetOpenAuth.OAuth2.ClientBase

A base class for common OAuth Client behaviors.
Show file Open project: OneCare/dotnetopenid Class Usage Examples

Public Methods

Method Description
AuthorizeRequest ( HttpWebRequest request, IAuthorizationState authorization ) : void

Adds the OAuth authorization token to an outgoing HTTP request, renewing a (nearly) expired access token if necessary.

AuthorizeRequest ( HttpWebRequest request, string accessToken ) : void

Adds the necessary HTTP Authorization header to an HTTP request for protected resources so that the Service Provider will allow the request through.

ExchangeUserCredentialForToken ( string userName, string password, IEnumerable scopes = null ) : IAuthorizationState

Exchanges a resource owner's password credential for OAuth 2.0 refresh and access tokens.

GetClientAccessToken ( IEnumerable scopes = null ) : IAuthorizationState

Obtains an access token for accessing client-controlled resources on the resource server.

GetScopedAccessToken ( string refreshToken, HashSet scope ) : IAuthorizationState

Gets an access token that may be used for only a subset of the scope for which a given refresh token is authorized.

If the return value includes a new refresh token, the old refresh token should be discarded and replaced with the new one.

RefreshAuthorization ( IAuthorizationState authorization, System.TimeSpan skipIfUsefulLifeExceeds = null ) : bool

Refreshes a short-lived access token using a longer-lived refresh token with a new access token that has the same scope as the refresh token. The refresh token itself may also be refreshed.

This method may modify the value of the IAuthorizationState.RefreshToken property on the authorization parameter if the authorization server has cycled out your refresh token. If the parameter value was updated, this method calls IAuthorizationState.SaveChanges on that instance.

Protected Methods

Method Description
ClientBase ( DotNetOpenAuth.OAuth2.AuthorizationServerDescription authorizationServer, string clientIdentifier = null, string clientSecret = null ) : System

Initializes a new instance of the ClientBase class.

Private Methods

Method Description
ProportionalLifeRemaining ( IAuthorizationState authorization ) : double

Calculates the fraction of life remaining in an access token.

RequestAccessToken ( DotNetOpenAuth.OAuth2.Messages.ScopedAccessTokenRequest request, IEnumerable scopes = null ) : IAuthorizationState

Requests an access token using a partially .initialized request message.

UpdateAuthorizationWithResponse ( IAuthorizationState authorizationState, DotNetOpenAuth.OAuth2.Messages.AccessTokenSuccessResponse accessTokenSuccess ) : void

Updates the authorization state maintained by the client with the content of an outgoing response.

UpdateAuthorizationWithResponse ( IAuthorizationState authorizationState, DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationSuccessAccessTokenResponse accessTokenSuccess ) : void

Updates the authorization state maintained by the client with the content of an outgoing response.

UpdateAuthorizationWithResponse ( IAuthorizationState authorizationState, DotNetOpenAuth.OAuth2.Messages.EndUserAuthorizationSuccessAuthCodeResponse authorizationSuccess ) : void

Updates authorization state with a success response from the Authorization Server.

Method Details

AuthorizeRequest() public method

Adds the OAuth authorization token to an outgoing HTTP request, renewing a (nearly) expired access token if necessary.
public AuthorizeRequest ( HttpWebRequest request, IAuthorizationState authorization ) : void
request System.Net.HttpWebRequest The request for protected resources from the service provider.
authorization IAuthorizationState The authorization for this request previously obtained via OAuth.
return void

AuthorizeRequest() public static method

Adds the necessary HTTP Authorization header to an HTTP request for protected resources so that the Service Provider will allow the request through.
public static AuthorizeRequest ( HttpWebRequest request, string accessToken ) : void
request System.Net.HttpWebRequest The request for protected resources from the service provider.
accessToken string The access token previously obtained from the Authorization Server.
return void

ClientBase() protected method

Initializes a new instance of the ClientBase class.
protected ClientBase ( DotNetOpenAuth.OAuth2.AuthorizationServerDescription authorizationServer, string clientIdentifier = null, string clientSecret = null ) : System
authorizationServer DotNetOpenAuth.OAuth2.AuthorizationServerDescription The token issuer.
clientIdentifier string The client identifier.
clientSecret string The client secret.
return System

ExchangeUserCredentialForToken() public method

Exchanges a resource owner's password credential for OAuth 2.0 refresh and access tokens.
public ExchangeUserCredentialForToken ( string userName, string password, IEnumerable scopes = null ) : IAuthorizationState
userName string The resource owner's username, as it is known by the authorization server.
password string The resource owner's account password.
scopes IEnumerable The desired scope of access.
return IAuthorizationState

GetClientAccessToken() public method

Obtains an access token for accessing client-controlled resources on the resource server.
public GetClientAccessToken ( IEnumerable scopes = null ) : IAuthorizationState
scopes IEnumerable The desired scopes.
return IAuthorizationState

GetScopedAccessToken() public method

Gets an access token that may be used for only a subset of the scope for which a given refresh token is authorized.
If the return value includes a new refresh token, the old refresh token should be discarded and replaced with the new one.
public GetScopedAccessToken ( string refreshToken, HashSet scope ) : IAuthorizationState
refreshToken string The refresh token.
scope HashSet The scope subset desired in the access token.
return IAuthorizationState

RefreshAuthorization() public method

Refreshes a short-lived access token using a longer-lived refresh token with a new access token that has the same scope as the refresh token. The refresh token itself may also be refreshed.
This method may modify the value of the IAuthorizationState.RefreshToken property on the authorization parameter if the authorization server has cycled out your refresh token. If the parameter value was updated, this method calls IAuthorizationState.SaveChanges on that instance.
public RefreshAuthorization ( IAuthorizationState authorization, System.TimeSpan skipIfUsefulLifeExceeds = null ) : bool
authorization IAuthorizationState The authorization to update.
skipIfUsefulLifeExceeds System.TimeSpan If given, the access token will not be refreshed if its remaining lifetime exceeds this value.
return bool