diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/DotNetOpenAuth/OAuth/ConsumerBase.cs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/DotNetOpenAuth/OAuth/ConsumerBase.cs b/src/DotNetOpenAuth/OAuth/ConsumerBase.cs index 2af6988..d9fa889 100644 --- a/src/DotNetOpenAuth/OAuth/ConsumerBase.cs +++ b/src/DotNetOpenAuth/OAuth/ConsumerBase.cs @@ -76,6 +76,33 @@ namespace DotNetOpenAuth.OAuth { internal OAuthChannel OAuthChannel { get; set; } /// <summary> + /// Obtains an access token for a new account at the Service Provider via 2-legged OAuth. + /// </summary> + /// <param name="requestParameters">Any applicable parameters to include in the query string of the token request.</param> + /// <returns>The access token.</returns> + /// <remarks> + /// The token secret is stored in the <see cref="TokenManager"/>. + /// </remarks> + public string RequestNewClientAccount(IDictionary<string, string> requestParameters = null) { + // Obtain an unauthorized request token. Assume the OAuth version given in the service description. + var token = new UnauthorizedTokenRequest(this.ServiceProvider.RequestTokenEndpoint, this.ServiceProvider.Version) { + ConsumerKey = this.ConsumerKey, + }; + var tokenAccessor = this.Channel.MessageDescriptions.GetAccessor(token); + tokenAccessor.AddExtraParameters(requestParameters); + var requestTokenResponse = this.Channel.Request<UnauthorizedTokenResponse>(token); + this.TokenManager.StoreNewRequestToken(token, requestTokenResponse); + + var requestAccess = new AuthorizedTokenRequest(this.ServiceProvider.AccessTokenEndpoint, this.ServiceProvider.Version) { + RequestToken = requestTokenResponse.RequestToken, + ConsumerKey = this.ConsumerKey, + }; + var grantAccess = this.Channel.Request<AuthorizedTokenResponse>(requestAccess); + this.TokenManager.ExpireRequestTokenAndStoreNewAccessToken(this.ConsumerKey, requestTokenResponse.RequestToken, grantAccess.AccessToken, grantAccess.TokenSecret); + return grantAccess.AccessToken; + } + + /// <summary> /// Creates a web request prepared with OAuth authorization /// that may be further tailored by adding parameters by the caller. /// </summary> |