public async Task <AuthorizeResult> AuthorizeAsync(AuthorizeRequest request,
                                                           CancellationToken cancellationToken = default)
        {
            _logger.LogTrace("AuthorizeAsync");

            if (_options.Browser == null)
            {
                throw new InvalidOperationException("No browser configured.");
            }

            AuthorizeResult result = new AuthorizeResult
            {
                State = CreateAuthorizeState(request.ExtraParameters)
            };

            var browserOptions = new BrowserOptions(result.State.StartUrl, _options.RedirectUri)
            {
                Timeout     = TimeSpan.FromSeconds(request.Timeout),
                DisplayMode = request.DisplayMode
            };

            var browserResult = await _options.Browser.InvokeAsync(browserOptions, cancellationToken);

            if (browserResult.ResultType == BrowserResultType.Success)
            {
                result.Data = browserResult.Response;
                return(result);
            }

            result.Error = browserResult.Error ?? browserResult.ResultType.ToString();
            return(result);
        }
        private async Task <string> CreateUrlAsync(AuthorizeState state, string codeChallenge, object extraParameters)
        {
            var request = new AuthorizeRequest((await _options.GetProviderInformationAsync()).AuthorizeEndpoint);

            string responseType = null;

            if (_options.Style == OidcClientOptions.AuthenticationStyle.AuthorizationCode)
            {
                responseType = OidcConstants.ResponseTypes.Code;
            }
            else if (_options.Style == OidcClientOptions.AuthenticationStyle.Hybrid)
            {
                responseType = OidcConstants.ResponseTypes.CodeIdToken;
            }
            else
            {
                throw new InvalidOperationException("Unsupported authentication style");
            }

            var url = request.CreateAuthorizeUrl(
                clientId: _options.ClientId,
                responseType: responseType,
                scope: _options.Scope,
                redirectUri: state.RedirectUri,
                responseMode: _options.UseFormPost ? OidcConstants.ResponseModes.FormPost : null,
                nonce: state.Nonce,
                state: state.State,
                codeChallenge: codeChallenge,
                codeChallengeMethod: OidcConstants.CodeChallengeMethods.Sha256,
                extra: extraParameters);

            return(url);
        }
Beispiel #3
0
        internal string CreateAuthorizeUrl(string state, string nonce, string codeChallenge, object extraParameters)
        {
            _logger.LogTrace("CreateAuthorizeUrl");

            var parameters = CreateAuthorizeParameters(state, nonce, codeChallenge, extraParameters);
            var request    = new AuthorizeRequest(_options.ProviderInformation.AuthorizeEndpoint);

            return(request.Create(parameters));
        }
        private async Task <string> CreateUrlAsync(AuthorizeState state, string codeChallenge, object extraParameters)
        {
            var request = new AuthorizeRequest((await _options.GetProviderInformationAsync()).AuthorizeEndpoint);
            var url     = request.CreateAuthorizeUrl(
                clientId: _options.ClientId,
                responseType: OidcConstants.ResponseTypes.CodeIdToken,
                scope: _options.Scope,
                redirectUri: state.RedirectUri,
                responseMode: _options.UseFormPost ? OidcConstants.ResponseModes.FormPost : null,
                nonce: state.Nonce,
                codeChallenge: codeChallenge,
                codeChallengeMethod: OidcConstants.CodeChallengeMethods.Sha256,
                extra: extraParameters);

            return(url);
        }
        public async Task <AuthorizeResult> AuthorizeAsync(AuthorizeRequest request)
        {
            _logger.LogTrace("AuthorizeAsync");

            if (_options.Browser == null)
            {
                throw new InvalidOperationException("No browser configured.");
            }

            AuthorizeResult result = new AuthorizeResult
            {
                State = CreateAuthorizeState(request.ExtraParameters)
            };

            var browserOptions = new BrowserOptions(result.State.StartUrl, _options.RedirectUri)
            {
                Timeout     = TimeSpan.FromSeconds(request.Timeout),
                DisplayMode = request.DisplayMode
            };

            if (_options.ResponseMode == OidcClientOptions.AuthorizeResponseMode.FormPost)
            {
                browserOptions.ResponseMode = OidcClientOptions.AuthorizeResponseMode.FormPost;
            }
            else
            {
                browserOptions.ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect;
            }

            var browserResult = await _options.Browser.InvokeAsync(browserOptions);

            if (browserResult.ResultType == BrowserResultType.Success)
            {
                result.Data = browserResult.Response;
                return(result);
            }

            result.Error = browserResult.Error;
            return(result);
        }