/// <summary> /// Authorize a Request Token, thereby generating an associated Access Token. /// </summary> /// <param name="requestTokenKey">Key of the request token.</param> /// <param name="userAccount">The associated user account.</param> /// <param name="approvedScope">The optional scope parameters.</param> /// <param name="store">Token storage object to use.</param> public static void AuthorizeRequestToken(string requestTokenKey, string userAccount, string[] approvedScope, IServerTokenStore store) { ServerRequestToken requestToken = store.FindRequestToken(requestTokenKey); if (requestToken == null) { throw new TokenNotFoundException(String.Format(CultureInfo.InvariantCulture, "Request Token '{0}' is not present.", requestTokenKey)); } if (!String.IsNullOrEmpty(requestToken.AccessTokenKey)) { throw new TokenAlreadyAuthorizedException(String.Format(CultureInfo.InvariantCulture, "Request Token '{0}' is already authorized.", requestTokenKey)); } NameValueCollection nvc = new NameValueCollection(); nvc.Add(requestToken.Parameters); if (approvedScope != null) { nvc["scope"] = String.Join(" ", approvedScope); } else { nvc["scope"] = ""; } ServerAccessToken accessToken = new ServerAccessToken(requestToken.ConsumerKey, GenerateRandomValue(), GenerateRandomValue(), userAccount, nvc); requestToken.AccessTokenKey = accessToken.Key; store.StoreAccessToken(accessToken); store.StoreRequestToken(requestToken); }
/// <summary> /// Create a new Request Token using the given arguments, and store it using the supplied /// token storage. /// </summary> /// <param name="consumerKey">Key of the consumer that is making the request.</param> /// <param name="parameters">Additional parameters that will be stored in the Request Token.</param> /// <param name="store">Token storage provider.</param> /// <returns>A new ServerRequestToken.</returns> public static ServerRequestToken BuildAndStoreRequestToken(string consumerKey, NameValueCollection parameters, IServerTokenStore store) { ServerRequestToken requestToken = new ServerRequestToken(consumerKey, GenerateRandomValue(), GenerateRandomValue(), null, parameters); store.StoreRequestToken(requestToken); return requestToken; }