我们有一个React,最初使用SPA模板创建,运行在.NET Core 3预览7上。React“客户机”被配置为隐式流,并成功地使用了oidc客户端。都在工作。
下面是我的startup.cs中的客户端配置:
var mySPAClient = new IdentityServer4.Models.Client()
{
AccessTokenLifetime = accessTokenLifetime,
RedirectUris =
{
$"{host}/authentication/login-callback",
$"{host}/silent-refresh.html"
},
PostLogoutRedirectUris =
{
$"{host}/authentication/logout-callback"
},
ClientId = "projectName.web",
AllowedScopes =
{
"projectName.webAPI",
"openid",
"profile"
},
ClientName = "projectName.web",
RequireConsent = false,
AllowedGrantTypes =
{
IdentityModel.OidcConstants.GrantTypes.Implicit
},
AllowAccessTokensViaBrowser = true,
};
但现在,当我升级到预览8的任何程序集,即预览7,我将在日志中得到以下错误
客户端的错误无效授予类型:"authorization_code" AuthorizeRequestValidationLog { ClientId:"projectName.web",ClientName:"projectName.web",RedirectUri:"https://localhost:44343/authentication/login-callback",AllowedRedirectUris:["https://localhost:44343/authentication/login-callback","https://localhost:44343/silent-refresh.html"],SubjectId:“匿名”,ResponseType:“代码”,ResponseMode:"query",GrantType:"authorization_code",GrantType:“,State:”,:null,Nonce: null,:null,:null,PromptMode: null,MaxAge: null,LoginHint: null,SessionId: null,Raw:[("client_id":"projectName.web"),("redirect_uri":"https://localhost:44343/authentication/login-callback"),("response_type":“代码”),(“范围”:"projectName.webAPI openid配置文件“),(”状态“:"a1e84334a8c94b7db599ddb9336447c8"),("code_challenge":MaxAge ("code_challenge_method":"S256") ),(“提示”:“无”)} (IdentityServer4.Validation.AuthorizeRequestValidator) 10:55:34错误请求验证失败(IdentityServer4.Endpoints.AuthorizeEndpoint)
我不知道为什么它现在指的是authorization_code,这个错误出现了吗?
为任何帮助而欢呼
发布于 2019-09-03 04:06:40
将response_type
改为"token"
而不是"code"
,您应该会没事的
更新:
确保提供正确的authority, client_id, response_type, scope
设置
发布于 2019-09-24 03:41:48
我已经算出我的了。但不确定它是否适用于你的。在我的例子中的问题是,我有一个流程流,在某种程度上是不匹配的。当我试图修改使用EF的Auth示例的React时,updateState调用不是在AuthorizeService.js/completeSignIn()
中进行的。在返回到SignIn()
之前,代码似乎会导致对令牌端点的另一次调用,没有updateState()
调用来保存状态。第二次调用失败,因为代码在第一次调用后过期。我以某种方式从requisite示例中找到了另一个源代码,它在updateState()
中具有必需的completeSignIn()
调用。除了非常不同的AuthorizeService.js文件之外,其他与身份验证/授权相关的代码在Auth示例和Redux示例之间是相同的。这是新的completeSignIn代码:
async completeSignIn(url) {
await this.ensureUserManagerInitialized();
try {
const { state } = await this.userManager.readSigninResponseState(url, this.userManager.settings.stateStore);
if (state.request_type === 'si:r' || !state.request_type) {
let user = await this.userManager.signinRedirectCallback(url);
this.updateState(user);
return this.success(state.data.userState);
}
if (state.request_type === 'si:p') {
await this.userManager.signinSilentCallback(url);
return this.success(undefined);
}
if (state.request_type === 'si:s') {
await this.userManager.signinSilentCallback(url);
return this.success(undefined);
}
throw new Error(`Invalid login mode '${state.request_type}'.`);
} catch (signInResponseError) {
console.log('There was an error signing in', signInResponseError);
return this.error('Sing in callback authentication error.');
}
}
https://stackoverflow.com/questions/57764059
复制相似问题