コード例 #1
0
        /// <summary>
        /// Acquires a token with the given parameters.
        /// </summary>
        /// <remarks>
        /// This method first tries to acquire the token silently using the <see cref="AcquireTokenSilentAsync"/> method.
        /// If that failes, then the interactive option is used using the <see cref="AcquireTokenInteractiveAsync"/> method.
        /// </remarks>
        /// <param name="request">Defines how to request for a token.</param>
        public async Task <AuthenticationResult> AcquireTokenAsync(TokenAcquisitionRequest request)
        {
            AuthenticationResult result = null;

            // If prompt is specified, and it is something else than None, then we must skip the silent acquisition.

            if (!request.Prompt.HasValue || request.Prompt == LoginPrompt.None)
            {
                try
                {
                    result = await this.AcquireTokenSilentAsync(request);
                }
                // Deliberately just swallowing any error, since if we cannot get a token this way, then we use another fallback method.
                catch (FailureCallbackException) { }
            }

            if (null == result)
            {
                try
                {
                    result = await this.AcquireTokenInteractiveAsync(request);
                }
                catch (FailureCallbackException) { }
            }

            return(result);
        }
コード例 #2
0
        /// <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);
        }
コード例 #3
0
        /// <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);
            }
        }
コード例 #4
0
        /// <summary>
        /// Acquires a token interactively asking the user for input. Depending on your application's configuration, the token is acquired either using
        /// a popup dialog, or by redirecting the user to the login.
        /// </summary>
        /// <param name="request">Defines how to request for a token.</param>
        public async Task <AuthenticationResult> AcquireTokenInteractiveAsync(TokenAcquisitionRequest request)
        {
            if (this.Options.InteractiveLoginMode == InteractiveLoginMode.Popup)
            {
                return(await this.AcquireTokenPopupAsync(request));
            }
            else if (this.Options.InteractiveLoginMode == InteractiveLoginMode.Redirect)
            {
                await this.AcquireTokenRedirectAsync(request);
            }

            return(null);
        }
コード例 #5
0
        /// <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);
        }