[英]Get bootStrapContext token from ClaimsPrincipal in MVC application
I am developing application in MVC and i want to authenticate my users with Azure active directory. 我正在开发MVC中的应用程序,我想用Azure活动目录验证我的用户。
To achieve this, I have created application in Azure active directory with the application URL and also assigned permissions to application. 为此,我使用应用程序URL在Azure活动目录中创建了应用程序,并为应用程序分配了权限。
I have also configured my application to use Azure AD authentication. 我还配置了我的应用程序以使用Azure AD身份验证。 Now when i try to access the bootstrapContext.Token, it comes always null.
现在,当我尝试访问bootstrapContext.Token时,它始终为null。
I am using below method to access the bootstrapContext. 我使用下面的方法来访问bootstrapContext。
var bootstrapContext = ClaimsPrincipal.Current.Identities.First().BootstrapContext as System.IdentityModel.Tokens.BootstrapContext;
string userAccessToken = bootstrapContext.Token;
I have searched on this and found that i have to update my web.config. 我搜索了这个,发现我必须更新我的web.config。 So i have updated it as below
所以我更新了如下
<system.identityModel>
<identityConfiguration saveBootstrapContext="true">
<system.identityModel>
My main goal is to use UserAssertion for authContext.AcquireToken method. 我的主要目标是将UserAssertion用于authContext.AcquireToken方法。 And UserAssertion requires bootstrapContext.Token.
UserAssertion需要bootstrapContext.Token。
As per suggestion from MvdD, I have also tried below thing 根据MvdD的建议,我也试过下面的事情
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = metadataUri,
TokenValidationParameters = new TokenValidationParameters
{
SaveSigninToken = true
}
});
but now, i am getting below error 但现在,我正在低于错误
AADSTS50027: Invalid JWT token. AADSTS50027: Invalid JWT token. Token format not valid.
Trace ID: 0d052707-9aaf-4037-b7c9-4c4aa7cfcc72
Correlation ID: 9a00573b-cfe9-4665-ab81-c0a03eace9d8
Timestamp: 2016-02-08 05:18:01Z
So can anyone help me on this ? 所以有人可以帮我吗?
It's not really clear from your question which protocol or what libraries you are using. 从您的问题来看,您使用的是哪种协议或哪些库并不是很清楚。
If you are using Katana middleware, you should set the SaveSigninToken
property in the appropriate AuthenticationOptions
class. 如果您使用的是Katana中间件,则应在相应的
AuthenticationOptions
类中设置SaveSigninToken
属性。 For the WS-Federation protocol, it would look something like this: app.UseWsFederationAuthentication( 对于WS-Federation协议,它看起来像这样:app.UseWsFederationAuthentication(
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = metadataUri,
TokenValidationParameters = new TokenValidationParameters
{
SaveSigninToken = true
}
}
);
If you are using System.IdentityModel
, you need to set the SaveBootstrapContext
property on the IdentityConfiguration
object. 如果您使用的是
System.IdentityModel
,则需要在IdentityConfiguration
对象上设置SaveBootstrapContext
属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.