我们已经将ASP.NET身份核用于Google服务提供商。以下是下面显示的代码
services
.AddAuthentication()
.AddGoogle(o => {
o.ClientId = "xxx";
o.ClientSecret = "xx";
// Tried using this event but no luck it is stucked
// and not going anywhere
o.Events.OnRedirectToAuthorizationEndpoint = ctx => {
o.ClientId = "xxx";
o.ClientSecret = "xxx";
return Task.CompletedTask;
};
});
但是我们想根据请求登录页面的用户动态更改clientId和clientSecret。我们可以根据请求更新clientId和clientSecret还是仅在启动时设置。
我们看到唯一的选择是使用原始的Google oauth api更改clientId和clientSecret。我们可以使用ASP.NET身份本身还是任何nuget包来做到这一点?任何帮助将不胜感激。
答案 0 :(得分:0)
最终可以使用下面的代码来解决
services
.AddAuthentication()
.AddGoogle(o => {
o.ClientId = "xxx";
o.ClientSecret = "xx";
o.Events.OnRedirectToAuthorizationEndpoint = ctx => {
ctx.Options.ClientId = "updated_clientId";
ctx.Options.ClientSecret = "updated_secret";
// This must be need to redirect the output
// You can access users HttpContext
// also make sure to replace redirectUri based on clientId
ctx.HttpContext.Response.Redirect(ctx.RedirectUri);
return Task.CompletedTask;
};
});