C# Class Glipho.OAuth.Providers.TokenManager

Implementation of the IServiceProviderTokenManager interface from DotNetOpenAuth.
Inheritance: IServiceProviderTokenManager
Show file Open project: Glipho/oauth-providers Class Usage Examples

Public Methods

Method Description
AuthoriseRequestToken ( string username, IServiceProviderRequestToken requestToken ) : bool

Authorise a request token by adding a user to it.

ExpireRequestTokenAndStoreNewAccessToken ( string consumerKey, string requestToken, string accessToken, string accessTokenSecret ) : void

Deletes a request token and its associated secret and stores a new access token and secret.

Any scope of granted privileges associated with the request token from the original call to TokenManager.StoreNewRequestToken(UnauthorizedTokenRequest,ITokenSecretContainingMessage) should be carried over to the new Access Token.

To associate a user account with the new access token, HttpContext.Current.User may be useful in an ASP.NET web application within the implementation of this method. Alternatively you may store the access token here without associating with a user account, and wait until WebConsumer.ProcessUserAuthorization or DesktopConsumer.ProcessUserAuthorization return the access token to associate the access token with a user account at that point.

GetAccessToken ( string token ) : IServiceProviderAccessToken

Gets details on the named access token.

It is acceptable for implementations to find the token, see that it has expired, delete it from the database and then throw KeyNotFoundException, or alternatively it can return the expired token anyway and the OAuth channel will log and throw the appropriate error.

GetConsumer ( string consumerKey ) : IConsumerDescription

Gets the Consumer description for a given a Consumer Key.

GetRequestToken ( string token ) : IServiceProviderRequestToken

Gets details on the named request token.

It is acceptable for implementations to find the token, see that it has expired, delete it from the database and then throw KeyNotFoundException, or alternatively it can return the expired token anyway and the OAuth channel will log and throw the appropriate error.

GetTokenSecret ( string token ) : string

Gets the Token Secret given a request or access token.

GetTokenType ( string token ) : TokenType

Classifies a token as a request token or an access token.

IsRequestTokenAuthorized ( string requestToken ) : bool

Checks whether a given request token has already been authorized by some user for use by the Consumer that requested it.

StoreNewRequestToken ( DotNetOpenAuth.OAuth.Messages.UnauthorizedTokenRequest request, ITokenSecretContainingMessage response ) : void

Stores a newly generated unauthorized request token, secret, and optional application-specific parameters for later recall.

Request tokens stored by this method SHOULD NOT associate any user account with this token. It usually opens up security holes in your application to do so. Instead, you associate a user account with access tokens (not request tokens) in the TokenManager.ExpireRequestTokenAndStoreNewAccessToken(string, string, string, string) method.

TokenManager ( Database consumers, Database issuedTokens ) : System

Initialises a new instance of the TokenManager class.

UpdateToken ( IServiceProviderRequestToken token ) : void

Persists any changes made to the token.

This library will invoke this method after making a set of changes to the token as part of a web request to give the host the opportunity to persist those changes to a database. Depending on the object persistence framework the host site uses, this method MAY not need to do anything (if changes made to the token will automatically be saved without any extra handling).

Method Details

AuthoriseRequestToken() public method

Authorise a request token by adding a user to it.
Thrown if a parameter is not valid. Thrown if a parameter is null. Thrown if an error occurs while executing the requested command.
public AuthoriseRequestToken ( string username, IServiceProviderRequestToken requestToken ) : bool
username string The username of the user to authorise the request token with.
requestToken IServiceProviderRequestToken The request token being authorised.
return bool

ExpireRequestTokenAndStoreNewAccessToken() public method

Deletes a request token and its associated secret and stores a new access token and secret.

Any scope of granted privileges associated with the request token from the original call to TokenManager.StoreNewRequestToken(UnauthorizedTokenRequest,ITokenSecretContainingMessage) should be carried over to the new Access Token.

To associate a user account with the new access token, HttpContext.Current.User may be useful in an ASP.NET web application within the implementation of this method. Alternatively you may store the access token here without associating with a user account, and wait until WebConsumer.ProcessUserAuthorization or DesktopConsumer.ProcessUserAuthorization return the access token to associate the access token with a user account at that point.

Thrown if a parameter is not valid. Thrown if an error occurs while executing the requested command.
public ExpireRequestTokenAndStoreNewAccessToken ( string consumerKey, string requestToken, string accessToken, string accessTokenSecret ) : void
consumerKey string The Consumer that is exchanging its request token for an access token.
requestToken string The Consumer's request token that should be deleted/expired.
accessToken string The new access token that is being issued to the Consumer.
accessTokenSecret string The secret associated with the newly issued access token.
return void

GetAccessToken() public method

Gets details on the named access token.
It is acceptable for implementations to find the token, see that it has expired, delete it from the database and then throw KeyNotFoundException, or alternatively it can return the expired token anyway and the OAuth channel will log and throw the appropriate error.
Thrown if a parameter is not valid. Thrown if the token cannot be found. Thrown if an error occurs while executing the requested command.
public GetAccessToken ( string token ) : IServiceProviderAccessToken
token string The access token.
return IServiceProviderAccessToken

GetConsumer() public method

Gets the Consumer description for a given a Consumer Key.
Thrown if a parameter is not valid. Thrown if the consumer key cannot be found. Thrown if an error occurs while executing the requested command.
public GetConsumer ( string consumerKey ) : IConsumerDescription
consumerKey string The Consumer Key.
return IConsumerDescription

GetRequestToken() public method

Gets details on the named request token.
It is acceptable for implementations to find the token, see that it has expired, delete it from the database and then throw KeyNotFoundException, or alternatively it can return the expired token anyway and the OAuth channel will log and throw the appropriate error.
Thrown if a parameter is not valid. Thrown if the token cannot be found. Thrown if an error occurs while executing the requested command.
public GetRequestToken ( string token ) : IServiceProviderRequestToken
token string The request token.
return IServiceProviderRequestToken

GetTokenSecret() public method

Gets the Token Secret given a request or access token.
Thrown if the secret cannot be found for the given token. Thrown if an error occurs while executing the requested command.
public GetTokenSecret ( string token ) : string
token string The request or access token.
return string

GetTokenType() public method

Classifies a token as a request token or an access token.
Thrown if a parameter is not valid. Thrown if an error occurs while executing the requested command.
public GetTokenType ( string token ) : TokenType
token string The token to classify.
return TokenType

IsRequestTokenAuthorized() public method

Checks whether a given request token has already been authorized by some user for use by the Consumer that requested it.
Thrown if an error occurs while executing the requested command.
public IsRequestTokenAuthorized ( string requestToken ) : bool
requestToken string The Consumer's request token.
return bool

StoreNewRequestToken() public method

Stores a newly generated unauthorized request token, secret, and optional application-specific parameters for later recall.
Request tokens stored by this method SHOULD NOT associate any user account with this token. It usually opens up security holes in your application to do so. Instead, you associate a user account with access tokens (not request tokens) in the TokenManager.ExpireRequestTokenAndStoreNewAccessToken(string, string, string, string) method.
Thrown if the consumer key is not registered, or a required parameter was not found in the parameters collection. Thrown if a parameter is null. Thrown if an error occurs while executing the requested command.
public StoreNewRequestToken ( DotNetOpenAuth.OAuth.Messages.UnauthorizedTokenRequest request, ITokenSecretContainingMessage response ) : void
request DotNetOpenAuth.OAuth.Messages.UnauthorizedTokenRequest The request message that resulted in the generation of a new unauthorized request token.
response ITokenSecretContainingMessage The response message that includes the unauthorized request token.
return void

TokenManager() public method

Initialises a new instance of the TokenManager class.
public TokenManager ( Database consumers, Database issuedTokens ) : System
consumers Database The consumers database client.
issuedTokens Database The issued tokens database client.
return System

UpdateToken() public method

Persists any changes made to the token.
This library will invoke this method after making a set of changes to the token as part of a web request to give the host the opportunity to persist those changes to a database. Depending on the object persistence framework the host site uses, this method MAY not need to do anything (if changes made to the token will automatically be saved without any extra handling).
Thrown if a parameter is null. Thrown if the is not a . Thrown if an error occurs while executing the requested command.
public UpdateToken ( IServiceProviderRequestToken token ) : void
token IServiceProviderRequestToken The token whose properties have been changed.
return void