Exemple #1
0
        public IActionResult Index(RequestToken request)
        {
            ResponseToken token;

            if (string.IsNullOrEmpty(request.Username))
            {
                return(BadRequest(ResponseTokenError.InvalidRequest("username")));
            }
            else if (string.IsNullOrEmpty(request.Password))
            {
                return(BadRequest(ResponseTokenError.InvalidRequest("password")));
            }

            var passwordBase = _oAuth2PasswordBaseService.GetPasswordBaseByUsername(request.Username);

            if (passwordBase == null)
            {
                return(Unauthorized(ResponseTokenError.UnauthorizedClient("invalid username")));
            }
            else if (passwordBase.Password != SHA512Helper.Crip(request.Password))
            {
                return(Unauthorized(ResponseTokenError.UnauthorizedClient("invalid password")));
            }

            token = TokenHelper.GenerateToken(passwordBase, _configuration["OAuth2Configuration:Key"], int.Parse(_configuration["OAuth2Configuration:Expires:Password"]), _configuration["OAuth2Configuration:Issuer"], _configuration["OAuth2Configuration:Audience"]);
            return(Ok(token));
        }
        public IActionResult Index(RequestToken request)
        {
            ResponseToken token;

            if (string.IsNullOrEmpty(request.Client_Id))
            {
                return(BadRequest(ResponseTokenError.InvalidRequest("client_id")));
            }
            else if (string.IsNullOrEmpty(request.Client_Secret))
            {
                return(BadRequest(ResponseTokenError.InvalidRequest("client_secret")));
            }

            var clientCredentialsBase = _oAuth2ClientCredentialsBaseService.GetClientCredentialsBaseByClientId(request.Client_Id);

            if (clientCredentialsBase == null)
            {
                return(Unauthorized(ResponseTokenError.UnauthorizedClient("invalid client_id")));
            }
            else if (clientCredentialsBase.ClientSecret != request.Client_Secret)
            {
                return(Unauthorized(ResponseTokenError.UnauthorizedClient("invalid client_secret")));
            }

            token = TokenHelper.GenerateToken(clientCredentialsBase, _configuration["OAuth2Configuration:Key"], int.Parse(_configuration["OAuth2Configuration:Expires:ClientCredentials"]), _configuration["OAuth2Configuration:Issuer"], _configuration["OAuth2Configuration:Audience"]);

            return(Ok(token));
        }
Exemple #3
0
        public IActionResult Index(RequestToken request)
        {
            ResponseToken token = new ResponseToken();

            if (string.IsNullOrEmpty(request.Device_Code))
            {
                return(BadRequest(ResponseTokenError.InvalidRequest("device_code")));
            }
            return(Ok(token));
        }
Exemple #4
0
        public IActionResult Index(RequestToken request)
        {
            if (string.IsNullOrEmpty(request.Code))
            {
                return(BadRequest(ResponseTokenError.InvalidRequest("code")));
            }
            else if (string.IsNullOrEmpty(request.Redirect_Uri))
            {
                return(BadRequest(ResponseTokenError.InvalidRequest("redirect_url")));
            }
            else if (string.IsNullOrEmpty(request.Client_Id))
            {
                return(BadRequest(ResponseTokenError.InvalidRequest("client_id")));
            }

            return(Ok());
        }
        public IActionResult Index(RequestToken request)
        {
            ResponseToken token;

            if (string.IsNullOrEmpty(request.Refresh_Token))
            {
                return(BadRequest(ResponseTokenError.InvalidRequest("refresh_token")));
            }

            var refreshTokenBase = _oAuth2RefreshTokenBaseService.GetRefreshTokenBaseByRefreshToken(request.Refresh_Token);

            if (refreshTokenBase == null)
            {
                return(Unauthorized(ResponseTokenError.UnauthorizedClient("invalid refresh_token")));
            }

            token = TokenHelper.GenerateToken(refreshTokenBase, _configuration["OAuth2Configuration:Key"], int.Parse(_configuration["OAuth2Configuration:Expires:RefreshToken"]), _configuration["OAuth2Configuration:Issuer"], _configuration["OAuth2Configuration:Audience"]);

            return(Ok(token));
        }