Identityserver3 在隐式流程中获取访问令牌
Identityserver3 getting accesstoken in a implicit flow
我们有一个带有隐式流和 CookieAuthentication 的 MVC 客户端。现在我们想从 javascript 调用另一个 api(相同的 STS),所以我们需要一个访问令牌。
问题:我们如何获得accesstoken。这是我们的 mvc 客户端设置:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies",
CookieName = "AuthCookieCoolApp",
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = ConfigurationManager.AppSettings["Authority"],
ClientId = "CoolApp",
RedirectUri = ConfigurationManager.AppSettings["RedirectUri"],
ResponseType = "id_token token", // added token here
SignInAsAuthenticationType = "Cookies",
Scope = "cool_profile openid profile",
}
使用 fiddler 我们看到 accesstoken 从 Identityserver 传回 redirceturi,但是我们如何获取它呢?我们在 OpenIdConnectAuthenticationOptions
上找到了 Notifications
属性,但事件的 none 似乎合适。
奖金问题:当我们在服务器 (mvc) 上获取访问令牌时,将其发送到浏览器的 perferd 方式是什么?将其存储在服务器上,并在可能需要调用新 api 的每个页面上发送它,或者在需要时从 javascript 请求它?
感谢您的指导
拉尔西
您可以从协议消息中获取访问令牌,例如:
Notifications = new OpenIdConnectAuthenticationNotifications
{
MessageReceived = notification =>
{
var message = notification.ProtocolMessage;
var accesstoken = message.AccessToken;
return Task.FromResult(0);
}
}
我们有一个带有隐式流和 CookieAuthentication 的 MVC 客户端。现在我们想从 javascript 调用另一个 api(相同的 STS),所以我们需要一个访问令牌。
问题:我们如何获得accesstoken。这是我们的 mvc 客户端设置:
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = "Cookies",
CookieName = "AuthCookieCoolApp",
});
app.UseOpenIdConnectAuthentication(new OpenIdConnectAuthenticationOptions
{
Authority = ConfigurationManager.AppSettings["Authority"],
ClientId = "CoolApp",
RedirectUri = ConfigurationManager.AppSettings["RedirectUri"],
ResponseType = "id_token token", // added token here
SignInAsAuthenticationType = "Cookies",
Scope = "cool_profile openid profile",
}
使用 fiddler 我们看到 accesstoken 从 Identityserver 传回 redirceturi,但是我们如何获取它呢?我们在 OpenIdConnectAuthenticationOptions
上找到了 Notifications
属性,但事件的 none 似乎合适。
奖金问题:当我们在服务器 (mvc) 上获取访问令牌时,将其发送到浏览器的 perferd 方式是什么?将其存储在服务器上,并在可能需要调用新 api 的每个页面上发送它,或者在需要时从 javascript 请求它?
感谢您的指导
拉尔西
您可以从协议消息中获取访问令牌,例如:
Notifications = new OpenIdConnectAuthenticationNotifications
{
MessageReceived = notification =>
{
var message = notification.ProtocolMessage;
var accesstoken = message.AccessToken;
return Task.FromResult(0);
}
}