public async void FailGracefullyOnHttpErrorInAccessTokenRequest() { OidcClient client = new OidcClient(new OktaConfig("testoktaid", "https://dev-00000.oktapreview.com", "com.test:/redirect", "com.test:/logout")); HttpMessageHandlerMock mockHttpClient = new HttpMessageHandlerMock(); mockHttpClient.Responder = (request) => { string url = request.Item1; Dictionary <string, string> data = request.Item2; return(new Tuple <System.Net.HttpStatusCode, string>( System.Net.HttpStatusCode.Forbidden, @"{ ""error"": ""not_authorized"", ""token_type"": ""testing""}")); }; client.SetHttpMock(mockHttpClient); client.OnLaunchBrowser = new Action <string>(url => { OidcClient.CaptureRedirectUrl(new Uri(client.Config.RedirectUri + "?code=12345&state=" + client.State_Internal)); }); await Assert.ThrowsAsync <OAuthException>(() => client.SignInWithBrowserAsync()); }
public async void RequestAccessToken() { OidcClient client = new OidcClient(new OktaConfig("testoktaid", "https://dev-00000.oktapreview.com", "com.test:/redirect", "com.test:/logout")); bool didRequestAccessToken = false; HttpMessageHandlerMock mockHttpClient = new HttpMessageHandlerMock(); mockHttpClient.Responder = (request) => { string url = request.Item1; Dictionary <string, string> data = request.Item2; Assert.StartsWith("https://dev-00000.oktapreview.com/oauth2/default/v1/token", url); Assert.Equal("12345", data["code"]); didRequestAccessToken = true; return(new Tuple <System.Net.HttpStatusCode, string>( System.Net.HttpStatusCode.OK, @"{ ""access_token"": ""access_token_example"", ""token_type"": ""testing""}")); }; client.SetHttpMock(mockHttpClient); client.OnLaunchBrowser = new Action <string>(url => { Assert.True( OidcClient.CaptureRedirectUrl(new Uri(client.Config.RedirectUri + "?code=12345&state=" + client.State_Internal))); }); await client.SignInWithBrowserAsync(); Assert.True(didRequestAccessToken); }
public async void SuccessfullyGetAccessToken() { OidcClient client = new OidcClient(new OktaConfig("testoktaid", "https://dev-00000.oktapreview.com", "com.test:/redirect", "com.test:/logout")); HttpMessageHandlerMock mockHttpClient = new HttpMessageHandlerMock(); mockHttpClient.Responder = (request) => { string url = request.Item1; Dictionary <string, string> data = request.Item2; return(new Tuple <System.Net.HttpStatusCode, string>( System.Net.HttpStatusCode.OK, @"{ ""access_token"": ""access_token_example"", ""token_type"": ""testing""}")); }; client.SetHttpMock(mockHttpClient); client.OnLaunchBrowser = new Action <string>(url => OidcClient.CaptureRedirectUrl(new Uri(client.Config.RedirectUri + "?code=12345&state=" + client.State_Internal))); StateManager state = await client.SignInWithBrowserAsync(); Assert.Equal("access_token_example", state.AccessToken); Assert.True(state.IsAuthenticated); }