I am developing application in MVC and i want to authenticate my users with Azure active directory.
To achieve this, I have created application in Azure active directory with the application URL and also assigned permissions to application.
I have also configured my application to use Azure AD authentication. Now when i try to access the bootstrapContext.Token, it comes always null.
I am using below method to access the 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. 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. And UserAssertion requires bootstrapContext.Token.
As per suggestion from MvdD, I have also tried below thing
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. For the WS-Federation protocol, it would look something like this:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With