public async Task LoginAsync() { try { var authConfig = await AuthorizationServiceConfiguration.FetchFromIssuerAsync(Uri.Parse("https://example.com")); AuthState authState = new AuthState(authConfig); AuthorizationRequest.Builder authReqBuilder = new AuthorizationRequest.Builder(authConfig, "RealOneGame.Xamarin", ResponseTypeValues.Code, Uri.Parse("https://com.example/oauth2redirect")); authReqBuilder.SetScope("api1 openid profile offline_access"); AuthorizationRequest authReq = authReqBuilder.Build(); AuthorizationService authService = new AuthorizationService(Application.Context); authService.PerformAuthorizationRequest(authReq, PendingIntent.GetActivity(Application.Context, 0, new Intent(Application.Context, typeof(MyAuthCompleteActivity)), 0), PendingIntent.GetActivity(Application.Context, 0, new Intent(Application.Context, typeof(MyAuthCanceledActivity)), 0)); } catch { } }
public async Task GetAuthorizationCode() { AppAuthConfiguration config = new AppAuthConfiguration.Builder() .SetBrowserMatcher(new BrowserBlacklist( VersionedBrowserMatcher.SamsungCustomTab, VersionedBrowserMatcher.FirefoxBrowser)) .Build(); AuthService = new AuthorizationService(CrossCurrentActivity.Current.Activity, config); //AuthState = new AuthState(); AuthorizationServiceConfiguration serviceConfig = await AuthorizationServiceConfiguration.FetchFromUrlAsync(Android.Net.Uri.Parse(DiscoveryEndpoint)); //TODO: update this to change string codeVerifier = "d129a4f8-c5c7-439d-b9c1-dd0349faba5cd129a4f8-c5c7-439d-b9c1-dd0349faba5c"; var authRequest = new AuthorizationRequest.Builder(serviceConfig, ClientId, ResponseTypeValues.Code, Android.Net.Uri.Parse(RedirectUri)) .SetScope("openid") .SetCodeVerifier(codeVerifier, codeVerifier, "plain") .Build(); AuthService.PerformAuthorizationRequest( authRequest, CreatePostAuthorizationIntent(CrossCurrentActivity.Current.Activity, authRequest, serviceConfig.DiscoveryDoc), AuthService.CreateCustomTabsIntentBuilder().SetToolbarColor(Color.ParseColor("#00a8e1")).Build()); }
private void MakeAuthRequest( AuthorizationServiceConfiguration serviceConfig, AuthState authState) { AuthorizationRequest authRequest; if (_promptStatus) { authRequest = new AuthorizationRequest.Builder( serviceConfig, Constants.ClientId, ResponseTypeValues.Code, Android.Net.Uri.Parse(Constants.RedirectUri)) .SetScope(string.Join(" ", Constants.Scopes)) .SetPrompt("login") .Build(); } else { authRequest = new AuthorizationRequest.Builder( serviceConfig, Constants.ClientId, ResponseTypeValues.Code, Android.Net.Uri.Parse(Constants.RedirectUri)) .SetScope(string.Join(" ", Constants.Scopes)) .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, NativeConstants.CLIENT_ID, ResponseTypeValues.Code, Android.Net.Uri.Parse(NativeConstants.REDIRECT_URI)) .SetScope("openid profile") .Build(); authService.PerformAuthorizationRequest( authRequest, TokenActivity.CreatePostAuthorizationIntent(this, authRequest, serviceConfig.DiscoveryDoc, authState)); }
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(); }
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, 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); }
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); }
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); } }
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); }