MSAL.js 令牌有效
MSAL.js token is valid
检查令牌如何有效?
我 运行 这个和后来我得到令牌,但我想检查是否有效
@action
signIn() {
const loginRequest = {
scopes: ["User.ReadWrite"]
}
this.userAgentApplication.loginRedirect(loginRequest);
this._isLoggedIn = true;
}
根据此处的文档:https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-spa-sign-in?tabs=javascript#sign-in-with-redirect
您需要注册一个回调函数才能 access/process 令牌。
The redirect methods don't return a promise because of the move away
from the main app. To process and access the returned tokens, you need
to register success and error callbacks before you call the redirect
methods.
function authCallback(error, response) {
//handle redirect response
}
myMsal.handleRedirectCallback(authCallback);
我认为令牌可能会在某处的响应中。
在应用程序的注册屏幕中,单击左侧的 API 权限边栏选项卡以打开我们添加对您的应用程序所需的 API 的访问权限的页面。
点击添加权限按钮,然后,
确保已 select 编辑了我的 APIs 选项卡。
在 API 列表中,select API TodoListService-ManualJwt。
在委派权限部分,select 列表中的访问权限 'TodoListService-ManualJwt'。如有必要,请使用搜索框。
点击底部的添加权限按钮。
public void ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
TokenValidationParameters = new TokenValidationParameters {
ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
},
});
}
请参考此文档
检查令牌如何有效?
我 运行 这个和后来我得到令牌,但我想检查是否有效
@action
signIn() {
const loginRequest = {
scopes: ["User.ReadWrite"]
}
this.userAgentApplication.loginRedirect(loginRequest);
this._isLoggedIn = true;
}
根据此处的文档:https://docs.microsoft.com/en-us/azure/active-directory/develop/scenario-spa-sign-in?tabs=javascript#sign-in-with-redirect 您需要注册一个回调函数才能 access/process 令牌。
The redirect methods don't return a promise because of the move away from the main app. To process and access the returned tokens, you need to register success and error callbacks before you call the redirect methods.
function authCallback(error, response) {
//handle redirect response
}
myMsal.handleRedirectCallback(authCallback);
我认为令牌可能会在某处的响应中。
在应用程序的注册屏幕中,单击左侧的 API 权限边栏选项卡以打开我们添加对您的应用程序所需的 API 的访问权限的页面。
点击添加权限按钮,然后, 确保已 select 编辑了我的 APIs 选项卡。 在 API 列表中,select API TodoListService-ManualJwt。 在委派权限部分,select 列表中的访问权限 'TodoListService-ManualJwt'。如有必要,请使用搜索框。 点击底部的添加权限按钮。
public void ConfigureAuth(IAppBuilder app)
{
app.UseWindowsAzureActiveDirectoryBearerAuthentication(
new WindowsAzureActiveDirectoryBearerAuthenticationOptions
{
Tenant = ConfigurationManager.AppSettings["ida:Tenant"],
TokenValidationParameters = new TokenValidationParameters {
ValidAudience = ConfigurationManager.AppSettings["ida:Audience"]
},
});
}
请参考此文档