Created
April 26, 2016 12:55
-
-
Save MisterJames/c818ad44950d1c7312e2d36b93041407 to your computer and use it in GitHub Desktop.
AddClaims method for GitHub Auth
This file contains hidden or 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
| private static void AddClaims(OAuthCreatingTicketContext context, JObject user) | |
| { | |
| var identifier = user.Value<string>("id"); | |
| if (!string.IsNullOrEmpty(identifier)) | |
| { | |
| context.Identity.AddClaim(new Claim( | |
| ClaimTypes.NameIdentifier, identifier, | |
| ClaimValueTypes.String, context.Options.ClaimsIssuer)); | |
| } | |
| var userName = user.Value<string>("login"); | |
| if (!string.IsNullOrEmpty(userName)) | |
| { | |
| context.Identity.AddClaim(new Claim( | |
| ClaimsIdentity.DefaultNameClaimType, userName, | |
| ClaimValueTypes.String, context.Options.ClaimsIssuer)); | |
| } | |
| var name = user.Value<string>("name"); | |
| if (!string.IsNullOrEmpty(name)) | |
| { | |
| context.Identity.AddClaim(new Claim( | |
| "urn:github:name", name, | |
| ClaimValueTypes.String, context.Options.ClaimsIssuer)); | |
| } | |
| var link = user.Value<string>("url"); | |
| if (!string.IsNullOrEmpty(link)) | |
| { | |
| context.Identity.AddClaim(new Claim( | |
| "urn:github:url", link, | |
| ClaimValueTypes.String, context.Options.ClaimsIssuer)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment