public async Task <IHttpActionResult> GetRequestToken(IdentityProviderType identityProvider) { string className = "RequestTokensController"; string methodName = "GetRequestToken"; string logEntry = $"IdentityProvider = {identityProvider}"; this.LogControllerStart(this.log, className, methodName, logEntry); var identityProviderCredentials = await this.appsManager.ReadIdentityProviderCredentials(this.AppHandle, identityProvider); // If no credentials found, or the credentials are missing material, throw internal server error if (identityProviderCredentials == null || string.IsNullOrEmpty(identityProviderCredentials.ClientId) || string.IsNullOrEmpty(identityProviderCredentials.ClientSecret) || string.IsNullOrEmpty(identityProviderCredentials.ClientRedirectUri)) { return(this.InternalServerError(new Exception("application credentials are incorrect in the developer portal."))); } string requestToken = null; try { requestToken = await this.identitiesManager.GetRequestToken( identityProvider, identityProviderCredentials.ClientId, identityProviderCredentials.ClientSecret, identityProviderCredentials.ClientRedirectUri); } catch (IdentityProviderException e) { Exception innerEx = e.InnerException; // If the innnerException is an HttpRequestException, this is a bad request // If it's an AuthException it's an internal server error if (innerEx is HttpRequestException) { // this corresponds to a bad request string badRequestMsg = ((HttpRequestException)innerEx).Message; return(this.BadRequest(badRequestMsg)); } else if (innerEx is OAuthException) { return(this.InternalServerError(innerEx)); } // Else return(this.InternalServerError(e)); } // The request token should not be null here GetRequestTokenResponse response = new GetRequestTokenResponse() { RequestToken = requestToken }; this.LogControllerEnd(this.log, className, methodName, logEntry); return(this.Ok(response)); }
internal void GetRequestTokenCompleted(IAsyncResult result) { GetRequestTokenResponse requestTokenResponse = _authenticationService.EndGetRequestToken(result); _applicationSettingsProvider[REQUEST_TOKEN] = requestTokenResponse.RequestToken; IsVerificationDetailsVisible = true; Messenger.Default.Send(requestTokenResponse.AuthorizationUri); }
public void AuthorizeWithPIN_ShouldAuthorizeUser() { GetRequestTokenResponse requestTokenResponse = new GetRequestTokenResponse { AuthorizationUri = new Uri("http://twitter.com/login"), RequestToken = new OAuthRequestToken() }; Mock.Get(_mockApplicationSettingsProvider) .SetupGet(m => m["requestToken"]).Returns(requestTokenResponse.RequestToken); Mock.Get(_mockAuthenticationService) .Setup(m => m.BeginLogin(It.IsAny <LoginRequest>(), It.IsAny <AsyncCallback>(), null)); _viewModel.AuthorizeWithPin(); Mock.Get(_mockApplicationSettingsProvider).VerifyAll(); Mock.Get(_mockAuthenticationService).VerifyAll(); }
public void AuthorizeWithPIN_ShouldAuthorizeUser() { GetRequestTokenResponse requestTokenResponse = new GetRequestTokenResponse { AuthorizationUri = new Uri("http://twitter.com/login"), RequestToken = new OAuthRequestToken() }; Mock.Get(_mockApplicationSettingsProvider) .SetupGet(m => m["requestToken"]).Returns(requestTokenResponse.RequestToken); Mock.Get(_mockAuthenticationService) .Setup(m => m.BeginLogin(It.IsAny<LoginRequest>(), It.IsAny<AsyncCallback>(), null)); _viewModel.AuthorizeWithPin(); Mock.Get(_mockApplicationSettingsProvider).VerifyAll(); Mock.Get(_mockAuthenticationService).VerifyAll(); }
public void GetRequestToken_ShouldReturnRequestTokenResponse() { OAuthRequestToken requestToken = new OAuthRequestToken(); Uri authorizationUri = new Uri("http://Twitter.com/xyz"); Mock.Get(_mockTwitterService) .Setup(mockService => mockService.GetRequestToken()) .Returns(requestToken); Mock.Get(_mockTwitterService) .Setup(mockService => mockService.GetAuthorizationUri(requestToken)) .Returns(authorizationUri); GetRequestTokenResponse requestTokenResponse = _authenticationService.GetRequestToken(); Mock.Get(_mockTwitterService).VerifyAll(); Assert.AreEqual(requestToken, requestTokenResponse.RequestToken); Assert.AreEqual(authorizationUri, requestTokenResponse.AuthorizationUri); }
public void GetRequestTokenCompleted_WithSuccess_ShouldRedirectUserToVerificationPage() { GetRequestTokenResponse requestTokenResponse = new GetRequestTokenResponse { AuthorizationUri = new Uri("http://twitter.com/AuthorizeApp/NGTweet"), RequestToken = new OAuthRequestToken() }; Mock.Get(_mockAuthenticationService) .Setup(m => m.EndGetRequestToken(It.IsAny <IAsyncResult>())) .Returns(requestTokenResponse); Mock.Get(_mockApplicationSettingsProvider) .SetupSet(m => m["requestToken"] = requestTokenResponse.RequestToken); _viewModel.GetRequestTokenCompleted(new Mock <IAsyncResult>().Object); Assert.IsFalse(_viewModel.IsAuthenticUser); Assert.IsTrue(_viewModel.IsVerificationDetailsVisible); Mock.Get(_mockAuthenticationService).VerifyAll(); Mock.Get(_mockApplicationSettingsProvider).VerifyAll(); }
public void GetRequestTokenCompleted_WithSuccess_ShouldRedirectUserToVerificationPage() { GetRequestTokenResponse requestTokenResponse = new GetRequestTokenResponse { AuthorizationUri = new Uri("http://twitter.com/AuthorizeApp/NGTweet"), RequestToken = new OAuthRequestToken() }; Mock.Get(_mockAuthenticationService) .Setup(m => m.EndGetRequestToken(It.IsAny<IAsyncResult>())) .Returns(requestTokenResponse); Mock.Get(_mockApplicationSettingsProvider) .SetupSet(m => m["requestToken"] = requestTokenResponse.RequestToken); _viewModel.GetRequestTokenCompleted(new Mock<IAsyncResult>().Object); Assert.IsFalse(_viewModel.IsAuthenticUser); Assert.IsTrue(_viewModel.IsVerificationDetailsVisible); Mock.Get(_mockAuthenticationService).VerifyAll(); Mock.Get(_mockApplicationSettingsProvider).VerifyAll(); }