public async Task <AuthInfo> LoginAsync() { try { var serviceConfiguration = await AuthorizationServiceConfiguration.FetchFromUrlAsync( Android.Net.Uri.Parse(Constants.DiscoveryEndpoint)); Console.WriteLine("configuration retrieved, proceeding"); MakeAuthRequest(serviceConfiguration, new AuthState()); await _loginResultWaitHandle.WaitAsync(); } catch (AuthorizationException ex) { Console.WriteLine("Failed to retrieve configuration:" + ex); } return(new AuthInfo() { IsAuthorized = _authState?.IsAuthorized ?? false, AccessToken = _authState?.AccessToken, IdToken = _authState?.IdToken, RefreshToken = _authState?.RefreshToken, Scope = _authState?.Scope }); }
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()); }
public async Task <AuthInfo> LoginAsync() { Console.WriteLine("LoginAsync"); try { var serviceConfiguration = await AuthorizationServiceConfiguration.FetchFromUrlAsync( Android.Net.Uri.Parse(Constants.DiscoveryEndpoint)); Console.WriteLine("configuration retrieved, proceeding"); //save discovery URL to format logout base URL Xamarin.Essentials.Preferences.Set("logoutUrl", serviceConfiguration.DiscoveryDoc.Issuer + "/v1/logout"); MakeAuthRequest(serviceConfiguration, new AuthState()); await _loginResultWaitHandle.WaitAsync(); } catch (AuthorizationException ex) { Console.WriteLine("Failed to retrieve configuration:" + ex); } return(new AuthInfo() { IsAuthorized = _authState?.IsAuthorized ?? false, AccessToken = _authState?.AccessToken, IdToken = _authState?.IdToken, RefreshToken = _authState?.RefreshToken, Scope = _authState?.Scope }); }
public async Task <AuthorizationResult> SignInAsync() { AuthorizationServiceConfiguration serviceConfiguration = await AuthorizationServiceConfiguration.FetchFromUrlAsync(ConfigurationEndpoint); BuildAuthorizationRequest(serviceConfiguration); BuildCompletedIntent(serviceConfiguration); return(await RequestAuthorization()); }
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); } }; }