public GetFormEncodedQueryFormat ( OAuthMessage message ) : string | ||
message | OAuthMessage | |
return | string |
private void AuthorizeTwoLegged() { var authorizeCodeRequest = BuildAuthorizationCodeRequest(); var serializer = new OAuthMessageSerializer(); var encodedQueryFormat = serializer.GetFormEncodedQueryFormat(authorizeCodeRequest); HttpWebRequest httpWebRequest = WebRequest.Create(authorizeCodeRequest.BaseUri) as HttpWebRequest; httpWebRequest.Method = "POST"; httpWebRequest.ContentType = "application/x-www-form-urlencoded"; StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()); streamWriter.Write(encodedQueryFormat); streamWriter.Close(); try { var message = serializer.Read(httpWebRequest.GetResponse() as HttpWebResponse) as EndUserAuthorizationResponse; if (message != null) { AuthorizeWithACS(message.Code); } } catch (WebException webex) { var message = serializer.Read(webex.Response as HttpWebResponse); var endUserAuthorizationFailedResponse = message as EndUserAuthorizationFailedResponse; if (endUserAuthorizationFailedResponse != null) { throw new AuthenticationException(endUserAuthorizationFailedResponse.ErrorDescription); } var userAuthorizationFailedResponse = message as ResourceAccessFailureResponse; if (userAuthorizationFailedResponse != null) { throw new AuthenticationException(userAuthorizationFailedResponse.ErrorDescription); } throw; } }
/// <summary> /// Authorizes the specified refresh token. /// </summary> /// <param name="refreshToken">The refresh token.</param> public void Authorize(string refreshToken) { var authorizeRequest = BuildAccessTokenRequest(refreshToken); var serializer = new OAuthMessageSerializer(); var encodedQueryFormat = serializer.GetFormEncodedQueryFormat(authorizeRequest); HttpWebRequest httpWebRequest = WebRequest.Create(authorizeRequest.BaseUri) as HttpWebRequest; httpWebRequest.Method = "POST"; httpWebRequest.ContentType = "application/x-www-form-urlencoded"; StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()); streamWriter.Write(encodedQueryFormat); streamWriter.Close(); try { var message = serializer.Read(httpWebRequest.GetResponse() as HttpWebResponse) as AccessTokenResponse; if (message != null) { CurrentAccessToken = message; LastAccessTokenRefresh = DateTime.UtcNow; } } catch (WebException webex) { var message = serializer.Read(webex.Response as HttpWebResponse); var endUserAuthorizationFailedResponse = message as EndUserAuthorizationFailedResponse; if (endUserAuthorizationFailedResponse != null) { throw new AuthenticationException(endUserAuthorizationFailedResponse.ErrorDescription); } var userAuthorizationFailedResponse = message as ResourceAccessFailureResponse; if (userAuthorizationFailedResponse != null) { throw new AuthenticationException(userAuthorizationFailedResponse.ErrorDescription); } throw; } }