我在.Net-Core中有一个自定义的.AddOAuth()实现。我已经使用Coinbase (基本上是add google实现的克隆,外加一些特定于coinbase的自定义选项) full source为身份验证创建了一个nuget包。我已经看过一些关于这方面的其他questions,但是它们似乎没有实现OAuth (例如,我不能传递作用域)我想使用OAuth登录,但我想给我的客户返回一个JWT。
当我尝试将JWT与AddCoinbase (它只是AddOAuth的一个派生物)一起使用时
services.AddAuthentication(JWT_BEARER_AUTH)
.AddJwtBearer(cfg =>
{
cfg.RequireHttpsMetadata = false;
cfg.SaveToken = true;
cfg.TokenValidationParameters = new TokenValidationParameters()
{
ValidIssuer = Configuration["Tokens:Issuer"],
ValidAudience = Configuration["Tokens:Issuer"],
//TODO: get key from secret section
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Tokens:Key"]))
};
})
.AddCoinbase(options => {
options.AccessAllAccounts = true;
options.SendLimitAmount = 1;
options.SendLimitCurrency = "USD";
options.SendLimitPeriod = SendLimitPeriod.day;
options.ClientId = Configuration["Coinbase:ClientId"];
options.ClientSecret = Configuration["Coinbase:ClientSecret"];
COINBASE_SCOPES.ForEach(scope => options.Scope.Add(scope));
options.SaveTokens = true;
options.ClaimActions.MapJsonKey("urn:coinbase:avatar", "avatar_url");
});登录到coinbase后,外部回调会重定向我
[HttpGet("ExternalLoginCallback")]
[AllowAnonymous]
public async Task<IActionResult> ExternalLoginCallback(string returnUrl = null, string remoteError = null)
{
if (remoteError != null)
{
//TODO: Handle remote error failure
throw new Exception($"Error from external provider: {remoteError}");
}
var info = await _signInManager.GetExternalLoginInfoAsync();
if (info == null)
{
//TODO: Handle null external login info
throw new Exception("Error: could not find user info");
}
// Sign in the user with this external login provider if the user already has a login.
var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, isPersistent: false, bypassTwoFactor: true);1
var user = await (result.Succeeded ?
_userManager.FindByLoginAsync(info.LoginProvider, info.ProviderKey)
: this.CreateIdentityUser(info));
await _signInManager.UpdateExternalAuthenticationTokensAsync(info);
_logger.LogInformation("User logged in with {Name} provider.", info.LoginProvider);
return Redirect(returnUrl);
}在重定向之后,我从未收到过JSON Web令牌,我总是收到Cookie。如何在向客户提供OAuth身份验证的同时利用JWT身份验证?
发布于 2019-01-31 10:31:31
OAuth不是Json Web Token解决方案。OIDC2.0提供授权和可选标识( OAuth )。
当您通过OAuth 2.0端点进行授权时,您将收到一个访问令牌和一个可选的ID令牌。ID令牌是一个带符号的JWT。访问令牌是一个不透明的对象,它是一些供应商实现的签名JWT,但不是所有的(Google是不透明的)。
授权后,您将收到一个或两个令牌(访问权限和ID)。您可以将它们包装在您自己的JWT中,对其进行签名,然后以任何您想要的方式使用组合的JWT。
https://stackoverflow.com/questions/54451807
复制相似问题