public Task OnCreatingTicketFuncAsync(OAuthCreatingTicketContext ctx) { // Get "State" property ctx.Properties.Items.TryGetValue("state", out var stateValue); if (string.IsNullOrWhiteSpace(stateValue)) { // Fail auth if state property is missing ctx.Fail("Discord Token JWT was missing in the 'State' parameter of the authentication request"); return(Task.CompletedTask); } ctx.Principal.Identities.First().AddClaim(new Claim("ReferralTokenId", stateValue)); return(Task.CompletedTask); }
public async static Task OnCreateTicketAsync(AuthenticationService serviceInstance, OAuthCreatingTicketContext context) { Claim emailClaim = context.Identity.FindFirst(claim => claim.Type == ClaimTypes.Email); if (emailClaim == null) { throw new OperationFailedException("Email claim is not present in login"); } IDictionary <string, string> claims = await serviceInstance.GetUserClaimsAsync(emailClaim.Value); if (claims.Count == 0) { // Don't let unknown users sign in context.Fail(new OperationFailedException()); return; } foreach (var claimKV in claims) { context.Identity.AddClaim(new Claim(claimKV.Key, claimKV.Value)); } }