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); }
public async void FailOnErrorInInitialRequest() { OidcClient client = new OidcClient(new OktaConfig("testoktaid", "https://dev-00000.oktapreview.com", "com.test:/redirect", "com.test:/logout")); client.OnLaunchBrowser = new Action <string>(url => { Assert.True( OidcClient.CaptureRedirectUrl(new Uri(client.Config.RedirectUri + "?error=test_error&state=" + client.State_Internal))); }); await Assert.ThrowsAsync <OAuthException>(() => client.SignInWithBrowserAsync()); }
public async void FailOnStateMismatchInInitialRequest() { OidcClient client = new OidcClient(new OktaConfig("testoktaid", "https://dev-00000.oktapreview.com", "com.test:/redirect", "com.test:/logout")); client.OnLaunchBrowser = new Action <string>(url => { Assert.False( OidcClient.CaptureRedirectUrl(new Uri(client.Config.RedirectUri + "?code=12345&state=fake_state"))); }); await Task.WhenAny(client.SignInWithBrowserAsync(), Task.Delay(1000)); }
protected override async void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); global::Android.Net.Uri uri_android = Intent.Data; if (OidcClient.CaptureRedirectUrl(new Uri(uri_android.ToString()))) { this.Finish(); } return; }
public async void CloseBrowserCorrectly() { OidcClient client = new OidcClient(new OktaConfig("testoktaid", "https://dev-00000.oktapreview.com", "com.test:/redirect", "com.test:/logout")); bool didCloseBrowser = false; client.OnCloseBrowser = () => { didCloseBrowser = true; }; client.OnLaunchBrowser = new Action <string>(url => { OidcClient.CaptureRedirectUrl(new Uri(client.Config.RedirectUri + "?code=12345&state=" + client.State_Internal)); }); await Task.WhenAny(client.SignInWithBrowserAsync(), Task.Delay(1000)); Assert.True(didCloseBrowser); }