Last active
August 29, 2015 13:57
-
-
Save benfoster/9409094 to your computer and use it in GitHub Desktop.
Refreshing claims using Federated Identity Session Authentication Module (SAM)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task RefreshClaimsAsync() | |
{ | |
SessionSecurityToken token; | |
if (FederatedAuthentication.SessionAuthenticationModule.TryReadSessionTokenFromCookie(out token)) | |
{ | |
// obtain their API access token using current identity | |
var accessToken = await tokenManager.GetTokenFromStoreAsync(token.ClaimsPrincipal.Identity.Name); | |
// Reload the claims | |
await WriteSessionToken(accessToken); | |
} | |
} | |
private async Task WriteSessionToken(ApiAccessToken accessToken) | |
{ | |
var client = ApiClient.FromConnectionString(Constants.CMSAPIConnectionStringName) | |
.Configure(cfg => cfg.UseSessionTokenAuthentication(accessToken.GetToken()).LogUsing(logger)); | |
var authClient = client.GetAuthClient(); | |
var identity = await authClient.GetIdentityAsync(); | |
var claimsPrincipal = new ClaimsPrincipal(new ClaimsIdentity(identity.GetClaims(), "Forms")); | |
logger.Trace("Writing SAM token to cookie."); | |
// Start SAM | |
var sessionToken = new SessionSecurityToken(claimsPrincipal); | |
FederatedAuthentication.SessionAuthenticationModule.WriteSessionTokenToCookie(sessionToken); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment