/// <summary> /// Acquires a token silently without user interaction. /// </summary> /// <param name="request">Defines how to request for a token.</param> public async Task <AuthenticationResult> AcquireTokenSilentAsync(TokenAcquisitionRequest request) { AuthenticationResult result = null; var module = await this.GetBlazoradeModuleAsync(); if (this.Options.InteractiveLoginMode == InteractiveLoginMode.Redirect) { try { result = await this.HandleRedirectPromiseAsync(); } catch { } } if (null == result) { var data = this.CreateMsalData(loginHint: request?.LoginHint, scopes: request?.Scopes, fallbackToDefaultLoginHint: request?.FallbackToDefaultLoginHint); using (var handler = new DotNetInstanceCallbackHandler <AuthenticationResult>(module, "acquireTokenSilent", data)) { result = await handler.GetResultAsync(timeout : request.Timeout ?? DefaultTimeout); } } return(result); }
/// <summary> /// Performs a logout of the current user. /// </summary> public async Task LogoutAsync() { var module = await this.GetBlazoradeModuleAsync(); var data = this.CreateMsalData(); using (var handler = new DotNetInstanceCallbackHandler(module, "logout", data)) { await handler.GetResultAsync(timeout : DefaultTimeout); } }
/// <summary> /// Acquires a token by redirecting the user to the identity provider. /// </summary> /// <param name="request">Defines how to request for a token.</param> public async Task AcquireTokenRedirectAsync(TokenAcquisitionRequest request) { var module = await this.GetBlazoradeModuleAsync(); var data = this.CreateMsalData(loginHint: request?.LoginHint, scopes: request?.Scopes, prompt: request?.Prompt); using (var handler = new DotNetInstanceCallbackHandler(module, "acquireTokenRedirect", data)) { await handler.GetResultAsync(timeout : request.Timeout ?? DefaultInteractiveTimeout); } }
/// <summary> /// Assumes that the current request is a redirect back from the identity provider, and attempt to process information sent back to the /// application from the identity provider. /// </summary> /// <remarks> /// Returns <c>null</c> if the current request is not a redirect back from the identity provider. /// </remarks> /// <exception cref="FailureCallbackException">The exception that is thrown if the current request is a redirect back from login, but the redirect specifies an error with the login.</exception> public async Task <AuthenticationResult> HandleRedirectPromiseAsync() { var module = await this.GetBlazoradeModuleAsync(); var data = this.CreateMsalData(navigateToLoginRequestUrl: false); AuthenticationResult result = null; using (var handler = new DotNetInstanceCallbackHandler <AuthenticationResult>(module, "handleRedirectPromise", data)) { result = await handler.GetResultAsync(timeout : DefaultTimeout); } return(result); }
/// <summary> /// Returns the default login hint for the current user. The default login hint is the login hint that was previously used to acquire a token. /// </summary> public async Task <string> GetDefaultLoginHintAsync() { var module = await this.GetBlazoradeModuleAsync(); var data = this.CreateMsalData(); string result = null; using (var handler = new DotNetInstanceCallbackHandler <string>(module, "getDefaultLoginHint", data)) { result = await handler.GetResultAsync(timeout : DefaultTimeout); } return(result); }
public async Task <AuthenticationResult> AuthenticateAsync(TokenAcquisitionRequest request) { request = request ?? new TokenAcquisitionRequest(); request.Scopes = request.Scopes ?? this.ApplicationSettings.DefaultScopes; var module = await this.GetBlazoradeTeamsJSModuleAsync(); await this.LocalStorage.SetItemAsync(request.CreateKey(this.ApplicationSettings.ClientId), request); var data = new Dictionary <string, object> { { "url", this.NavMan.ToAbsoluteUri(this.ApplicationSettings.LoginUrl) } }; string result = null; AuthenticationResult token = null; using (var handler = new DotNetInstanceCallbackHandler <string>(module, "authentication_authenticate", data)) { result = await handler.GetResultAsync(timeout : request.Timeout); } if (result?.Length > 0) { try { token = JsonSerializer.Deserialize <AuthenticationResult>(result); } catch { } } if (null == token) { this.AssertMsalService(); try { token = await this.MsalService.AcquireTokenSilentAsync(fallbackToDefaultLoginHint : true); } catch { } } return(token); }
/// <summary> /// Acquires a token with a popup dialog. /// </summary> /// <param name="request">Defines how to request for a token.</param> public async Task <AuthenticationResult> AcquireTokenPopupAsync(TokenAcquisitionRequest request) { if (null == request) { throw new ArgumentNullException(nameof(request)); } var module = await this.GetBlazoradeModuleAsync(); var data = this.CreateMsalData(loginHint: request?.LoginHint, scopes: request?.Scopes, prompt: request?.Prompt); AuthenticationResult result = null; using (var handler = new DotNetInstanceCallbackHandler <AuthenticationResult>(module, "acquireTokenPopup", data)) { result = await handler.GetResultAsync(timeout : request.Timeout ?? DefaultInteractiveTimeout); } return(result); }
/// <summary> /// Gets the settings for the current instance. /// </summary> public async Task <Settings> GetSettingsAsync() { var handler = new DotNetInstanceCallbackHandler <Settings>(await this.GetBlazoradeTeamsJSModuleAsync(), "settings_getSettings"); return(await handler.GetResultAsync()); }