Beispiel #1
0
        public async Task <IActionResult> GetToken([FromBody] TokenRequest tokenRequest)
        {
            try
            {
                TokenConfiguration tokenConfiguration = _configuration.GetSection("TokenConfiguration").Get <TokenConfiguration>();

                Token token = await _authenticationService.GetTokenAsync(tokenRequest, tokenConfiguration.Issuer, tokenConfiguration.Audiences,
                                                                         tokenConfiguration.ExpirationInMinutesAccessToken, tokenConfiguration.ExpirationInMinutesRefreshToken);

                return(APIResult(result: token));
            }
            catch (Exception ex)
            {
                return(APIResult(ex));
            }
        }
Beispiel #2
0
        public async Task <ActionResult <TokenResponse> > Token([FromForm] TokenRequest request, CancellationToken ct)
        {
            var client = await _ioAuthClientsService.GetByClientIdAsync(request.client_id, ct);

            if (!client.IsValid())
            {
                return(BadRequest("Client not found"));
            }

            if (!client.IsMatchRedirectUri(request))
            {
                return(BadRequest("Invalid redirect uri"));
            }

            if (!client.IsCorrectSecret(request))
            {
                return(BadRequest("Invalid client secret"));
            }

            var response = await _oauthService.GetTokenAsync(
                request.grant_type,
                request.code,
                request.username,
                request.password,
                request.refresh_token,
                IpAddress,
                UserAgent,
                client.Scopes.Select(x => x.Value).ToList(),
                client.Audience,
                ct);

            if (!response.error.IsEmpty())
            {
                return(BadRequest(response.error));
            }

            return(response);
        }