|
|
@ -12,6 +12,7 @@ using AspNet.Security.OpenIdConnect.Extensions; |
|
|
using AspNet.Security.OpenIdConnect.Server; |
|
|
using AspNet.Security.OpenIdConnect.Server; |
|
|
using JetBrains.Annotations; |
|
|
using JetBrains.Annotations; |
|
|
using Microsoft.AspNetCore.Authentication; |
|
|
using Microsoft.AspNetCore.Authentication; |
|
|
|
|
|
using Microsoft.AspNetCore.Builder; |
|
|
using Microsoft.AspNetCore.Http.Authentication; |
|
|
using Microsoft.AspNetCore.Http.Authentication; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.DependencyInjection; |
|
|
using Microsoft.Extensions.Logging; |
|
|
using Microsoft.Extensions.Logging; |
|
|
@ -39,8 +40,7 @@ namespace OpenIddict.Infrastructure { |
|
|
|
|
|
|
|
|
// Reject token requests using grant_type=authorization_code
|
|
|
// Reject token requests using grant_type=authorization_code
|
|
|
// if the authorization code flow support is not enabled.
|
|
|
// if the authorization code flow support is not enabled.
|
|
|
if (context.Request.IsAuthorizationCodeGrantType() && |
|
|
if (context.Request.IsAuthorizationCodeGrantType() && !services.Options.IsAuthorizationCodeFlowEnabled()) { |
|
|
!services.Options.GrantTypes.Contains(OpenIdConnectConstants.GrantTypes.AuthorizationCode)) { |
|
|
|
|
|
services.Logger.LogError("The token request was rejected because the authorization code flow was not enabled."); |
|
|
services.Logger.LogError("The token request was rejected because the authorization code flow was not enabled."); |
|
|
|
|
|
|
|
|
context.Reject( |
|
|
context.Reject( |
|
|
@ -52,8 +52,7 @@ namespace OpenIddict.Infrastructure { |
|
|
|
|
|
|
|
|
// Reject token requests using grant_type=client_credentials
|
|
|
// Reject token requests using grant_type=client_credentials
|
|
|
// if the client credentials flow support is not enabled.
|
|
|
// if the client credentials flow support is not enabled.
|
|
|
else if (context.Request.IsClientCredentialsGrantType() && |
|
|
else if (context.Request.IsClientCredentialsGrantType() && !services.Options.IsClientCredentialsFlowEnabled()) { |
|
|
!services.Options.GrantTypes.Contains(OpenIdConnectConstants.GrantTypes.ClientCredentials)) { |
|
|
|
|
|
services.Logger.LogError("The token request was rejected because the client credentials flow was not enabled."); |
|
|
services.Logger.LogError("The token request was rejected because the client credentials flow was not enabled."); |
|
|
|
|
|
|
|
|
context.Reject( |
|
|
context.Reject( |
|
|
@ -65,8 +64,7 @@ namespace OpenIddict.Infrastructure { |
|
|
|
|
|
|
|
|
// Reject token requests using grant_type=password if the
|
|
|
// Reject token requests using grant_type=password if the
|
|
|
// resource owner password credentials flow support is not enabled.
|
|
|
// resource owner password credentials flow support is not enabled.
|
|
|
else if (context.Request.IsPasswordGrantType() && |
|
|
else if (context.Request.IsPasswordGrantType() && !services.Options.IsPasswordFlowEnabled()) { |
|
|
!services.Options.GrantTypes.Contains(OpenIdConnectConstants.GrantTypes.Password)) { |
|
|
|
|
|
services.Logger.LogError("The token request was rejected because the resource " + |
|
|
services.Logger.LogError("The token request was rejected because the resource " + |
|
|
"owner password credentials flow was not enabled."); |
|
|
"owner password credentials flow was not enabled."); |
|
|
|
|
|
|
|
|
@ -79,8 +77,7 @@ namespace OpenIddict.Infrastructure { |
|
|
|
|
|
|
|
|
// Reject token requests using grant_type=refresh_token
|
|
|
// Reject token requests using grant_type=refresh_token
|
|
|
// if the refresh token flow support is not enabled.
|
|
|
// if the refresh token flow support is not enabled.
|
|
|
else if (context.Request.IsRefreshTokenGrantType() && |
|
|
if (context.Request.IsRefreshTokenGrantType() && !services.Options.IsRefreshTokenFlowEnabled()) { |
|
|
!services.Options.GrantTypes.Contains(OpenIdConnectConstants.GrantTypes.RefreshToken)) { |
|
|
|
|
|
services.Logger.LogError("The token request was rejected because the refresh token flow was not enabled."); |
|
|
services.Logger.LogError("The token request was rejected because the refresh token flow was not enabled."); |
|
|
|
|
|
|
|
|
context.Reject( |
|
|
context.Reject( |
|
|
@ -91,8 +88,7 @@ namespace OpenIddict.Infrastructure { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Reject token requests that specify scope=offline_access if the refresh token flow is not enabled.
|
|
|
// Reject token requests that specify scope=offline_access if the refresh token flow is not enabled.
|
|
|
if (context.Request.HasScope(OpenIdConnectConstants.Scopes.OfflineAccess) && |
|
|
if (context.Request.HasScope(OpenIdConnectConstants.Scopes.OfflineAccess) && !services.Options.IsRefreshTokenFlowEnabled()) { |
|
|
!services.Options.GrantTypes.Contains(OpenIdConnectConstants.GrantTypes.RefreshToken)) { |
|
|
|
|
|
context.Reject( |
|
|
context.Reject( |
|
|
error: OpenIdConnectConstants.Errors.InvalidRequest, |
|
|
error: OpenIdConnectConstants.Errors.InvalidRequest, |
|
|
description: "The 'offline_access' scope is not allowed."); |
|
|
description: "The 'offline_access' scope is not allowed."); |
|
|
|