Exemplo n.º 1
0
        private void MakeAuthRequest(AuthorizationServiceConfiguration serviceConfig, AuthState authState)
        {
            var authRequest = new AuthorizationRequest.Builder(
                serviceConfig, "nativeXamarin",
                $"{ResponseTypeValues.Code}",
                Android.Net.Uri.Parse("com.companyname.nativexamarin:/oauth2redirect"))
                              .SetScope("openid profile email")
                              .Build();
            var postAuthorizationIntent = CreatePostAuthorizationIntent(MainActivity.Instance, authRequest, serviceConfig.DiscoveryDoc, authState);

            _authService.PerformAuthorizationRequest(authRequest, postAuthorizationIntent);
        }
        private void MakeAuthRequest(AuthorizationServiceConfiguration serviceConfig, AuthState authState)
        {
            var authRequest = new AuthorizationRequest.Builder(serviceConfig, ClientId, ResponseTypeValues.Code, Android.Net.Uri.Parse(RedirectUri))
                              .SetScope("openid profile email")
                              .Build();

            Console.WriteLine("Making auth request to " + serviceConfig.AuthorizationEndpoint);
            authService.PerformAuthorizationRequest(
                authRequest,
                TokenActivity.CreatePostAuthorizationIntent(this, authRequest, serviceConfig.DiscoveryDoc, authState),
                authService.CreateCustomTabsIntentBuilder().SetToolbarColor(Resources.GetColor(Resource.Color.colorAccent)).Build());
        }
        private void BuildAuthorizationRequest(AuthorizationServiceConfiguration serviceConfiguration)
        {
            AuthorizationRequest.Builder builder = new AuthorizationRequest.Builder(
                serviceConfiguration,
                Configuration.ClientId,
                ResponseTypeValues.Code,
                Uri.Parse(Configuration.LoginRedirectUri));

            builder.SetScope(string.Join(" ", Scopes));

            authorizationRequest = builder.Build();
        }
Exemplo n.º 4
0
        private void MakeAuthRequest(AuthorizationServiceConfiguration serviceConfig, AuthState authState)
        {
            var authRequest = new AuthorizationRequest.Builder(
                serviceConfig, Constants.ClientId,
                $"{ResponseTypeValues.Code} {ResponseTypeValues.Token}",
                Android.Net.Uri.Parse(Constants.RedirectUri))
                              .SetScope(string.Join(" ", Constants.Scopes))
                              .SetResponseMode("query")
                              .Build();
            var postAuthorizationIntent = CreatePostAuthorizationIntent(MainActivity.Instance, authRequest, serviceConfig.DiscoveryDoc, authState);

            _authService.PerformAuthorizationRequest(authRequest, postAuthorizationIntent);
        }
Exemplo n.º 5
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_main);
            authService = new AuthorizationService(this);
            var idpButton = FindViewById <Button>(Resource.Id.button1);

            idpButton.Click += async delegate
            {
                AuthorizationServiceConfiguration serviceConfiguration = new AuthorizationServiceConfiguration(
                    Android.Net.Uri.Parse($"{NativeConstants.OPENID_BASE_URL}/authorization"),
                    Android.Net.Uri.Parse($"{NativeConstants.OPENID_BASE_URL}/token"),
                    Android.Net.Uri.Parse($"{NativeConstants.OPENID_BASE_URL}/registration"));
                MakeAuthRequest(serviceConfiguration, new AuthState());
            };
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_main);

            authService = new AuthorizationService(this);

            var idpButton = FindViewById <Button>(Resource.Id.idpButton);

            idpButton.Click += async delegate
            {
                Console.WriteLine("initiating auth...");

                try
                {
                    AuthorizationServiceConfiguration serviceConfiguration;
                    if (DiscoveryEndpoint != null)
                    {
                        serviceConfiguration = await AuthorizationServiceConfiguration.FetchFromUrlAsync(
                            Android.Net.Uri.Parse(DiscoveryEndpoint));
                    }
                    else
                    {
                        serviceConfiguration = new AuthorizationServiceConfiguration(
                            Android.Net.Uri.Parse(AuthEndpoint),
                            Android.Net.Uri.Parse(TokenEndpoint),
                            Android.Net.Uri.Parse(RegistrationEndpoint));
                    }

                    Console.WriteLine("configuration retrieved, proceeding");
                    if (ClientId == null)
                    {
                        // Do dynamic client registration if no client_id
                        MakeRegistrationRequest(serviceConfiguration);
                    }
                    else
                    {
                        MakeAuthRequest(serviceConfiguration, new AuthState());
                    }
                }
                catch (AuthorizationException ex)
                {
                    Console.WriteLine("Failed to retrieve configuration:" + ex);
                }
            };
        }
Exemplo n.º 7
0
        private void MakeAuthRequest(AuthorizationServiceConfiguration serviceConfig, AuthState authState)
        {
            var authRequest = new AuthorizationRequest.Builder(serviceConfig, Constants.ClientId,
                                                               ResponseTypeValues.Code, Android.Net.Uri.Parse(Constants.RedirectUri))
                              .SetScope("openid profile email offline_access")
                              .Build();

            Console.WriteLine("Making auth request to " + serviceConfig.AuthorizationEndpoint);

            var postAuthorizationIntent = CreatePostAuthorizationIntent(MainActivity.Instance, authRequest,
                                                                        serviceConfig.DiscoveryDoc, authState);

            var customTabsIntentBuilder = _authService.CreateCustomTabsIntentBuilder();
            var customTabsIntent        = customTabsIntentBuilder.Build();

            _authService.PerformAuthorizationRequest(authRequest, postAuthorizationIntent, customTabsIntent);
        }
Exemplo n.º 8
0
        public async Task <(bool IsSucessful, string Error)> Login(Urls.OIDCUrls urls)
        {
            var configuration = new AuthorizationServiceConfiguration(
                ToUrl(urls.Authorization),
                ToUrl(urls.Token)
                );

            var authRequestBuilder = new AuthorizationRequest.Builder(
                configuration,
                AuthConstants.ClientId,
                ResponseTypeValues.Code,
                global::Android.Net.Uri.Parse(AuthConstants.RedirectUri)
                ).SetScope(AuthConstants.Scope);

            if (AuthConstants.Scope.Contains("offline_access"))
            {
                authRequestBuilder = authRequestBuilder.SetPrompt("consent");
            }
            var authRequest = authRequestBuilder.Build();

            MicroLogger.LogDebug("Making auth request to " + configuration.AuthorizationEndpoint);
#pragma warning disable IDE0059 // Unnecessary assignment of a value
            var intent = authService.GetAuthorizationRequestIntent(authRequest);
#pragma warning restore IDE0059 // Unnecessary assignment of a value

            taskCompletitionSource = new TaskCompletionSource <AuthState>();

            authService.PerformAuthorizationRequest(
                authRequest,
                AuthActivity.CreatePostAuthorizationIntent(
                    _context,
                    authRequest),
                authService.CreateCustomTabsIntentBuilder().Build()
                );

            var state = await taskCompletitionSource.Task;
            if (state.AuthorizationException != null)
            {
                return(false, state.AuthorizationException.ErrorDescription);
            }
            else
            {
                return(true, null);
            }
        }
Exemplo n.º 9
0
        private void MakeAuthRequest(
            AuthorizationServiceConfiguration serviceConfig,
            AuthState authState)
        {
            var authRequest = new AuthorizationRequest.Builder(
                serviceConfig, Constants.ClientId,
                ResponseTypeValues.Code,
                Android.Net.Uri.Parse(Constants.RedirectUri))
                              .SetScope(string.Join(" ", Constants.Scopes))
                              .Build();

            Console.WriteLine("Making auth request to " + serviceConfig.AuthorizationEndpoint);

            var postAuthorizationIntent = CreatePostAuthorizationIntent(
                MainActivity.Instance, authRequest, serviceConfig.DiscoveryDoc, authState);

            _authService.PerformAuthorizationRequest(authRequest, postAuthorizationIntent);
        }
        /// <summary>
        /// Perform the authentication request
        /// </summary>
        /// <returns>The authenticate.</returns>
        /// <param name="authenticateOptions">Authenticate options.</param>
        override public Task <User> Authenticate(IAuthenticateOptions authenticateOptions)
        {
            AndroidAuthenticateOptions authOptions = (AndroidAuthenticateOptions)NonNull(authenticateOptions, "authenticateOptions");
            Activity fromActivity = NonNull(authOptions.FromActvity, "fromActivity");
            int      resultCode   = NonNull(authOptions.ResultCode, "resultCode");

            authenticateTaskComplete = new TaskCompletionSource <User>();
            authenticateTask         = authenticateTaskComplete.Task;

            AuthorizationServiceConfiguration authorizationServiceConfiguration = GetAuthorizationServiceConfiguration();

            authorizationService = GetAuthorizationService(fromActivity);
            authState            = new AuthState(authorizationServiceConfiguration);

            AuthorizationRequest authorizationRequest = new AuthorizationRequest.Builder(authorizationServiceConfiguration, keycloakConfig.ResourceId, ResponseTypeValues.Code, parseUri(authenticationConfig.RedirectUri))
                                                        .SetScopes(authenticationConfig.Scopes)
                                                        .Build();

            Intent authIntent = authorizationService.GetAuthorizationRequestIntent(authorizationRequest);

            fromActivity.StartActivityForResult(authIntent, resultCode);
            return(authenticateTask);
        }