Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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 Task <OktaState> SignIn(IOktaConfig oktaConfig = default)
        {
            oktaConfig = oktaConfig ?? OktaConfig.LoadFromPList("OktaConfig.plist");
            OidcClient oidcClient = new OidcClient(this, oktaConfig);

            return(await oidcClient.SignInWithBrowserAsync());
        }
Пример #5
0
        private async void FabOnClick(object sender, EventArgs eventArgs)
        {
            View view = (View)sender;

            OidcClient client = new OidcClient(this, await OktaConfig.LoadFromXmlStreamAsync(Assets.Open("OktaConfig.xml")));
            var        res    = await client.SignInWithBrowserAsync();

            res.AccessToken.Clone();
        }
Пример #6
0
        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());
        }
Пример #7
0
        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));
        }
Пример #8
0
        async partial void LoginBtn_TouchUpInside(UIButton sender)
        {
            var res = await client.SignInWithBrowserAsync();

            this.configTestView.Text = $"AccessToken: {res.AccessToken}\n" +
                                       $"IdToken: {res.IdToken}\n" +
                                       $"Expires: {res.Expires}\n" +
                                       $"Scope: {res.Scope}\n" +
                                       $"RefreshToken: {res.RefreshToken ?? "<none>"}\n" +
                                       $"TokenType: {res.TokenType}\n";

            res.AccessToken.Clone();
        }
Пример #9
0
        public async void LaunchBrowserCorrectly()
        {
            OidcClient client = new OidcClient(new OktaConfig("testoktaid", "https://dev-00000.oktapreview.com", "com.test:/redirect", "com.test:/logout"));

            bool didLaunchBrowser = false;

            client.OnLaunchBrowser = new Action <string>(url =>
            {
                Assert.StartsWith("https://dev-00000.oktapreview.com/oauth2/default/v1/authorize?", url);
                didLaunchBrowser = true;
            });

            await Task.WhenAny(client.SignInWithBrowserAsync(), Task.Delay(1000));

            Assert.True(didLaunchBrowser);
        }
Пример #10
0
        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);
        }