internal static Task OnCreatingTicket(TwitterCreatingTicketContext context) { if (context.Principal != null) { Helpers.ThrowIfConditionFailed(() => context.UserId == "valid_user_id", "UserId is not valid"); Helpers.ThrowIfConditionFailed(() => context.ScreenName == "valid_screen_name", "ScreenName is not valid"); Helpers.ThrowIfConditionFailed(() => context.AccessToken == "valid_oauth_token", "AccessToken is not valid"); Helpers.ThrowIfConditionFailed(() => context.AccessTokenSecret == "valid_oauth_token_secret", "AccessTokenSecret is not valid"); context.Principal.Identities.First().AddClaim(new Claim("ManageStore", "false")); } return Task.FromResult(0); }
/// <summary> /// Creates an <see cref="AuthenticationTicket"/> from the specified <paramref name="token"/>. /// </summary> /// <param name="identity">The <see cref="ClaimsIdentity"/>.</param> /// <param name="properties">The <see cref="AuthenticationProperties"/>.</param> /// <param name="token">The <see cref="AccessToken"/>.</param> /// <param name="user">The <see cref="JsonElement"/> for the user.</param> /// <returns>The <see cref="AuthenticationTicket"/>.</returns> protected virtual async Task <AuthenticationTicket> CreateTicketAsync( ClaimsIdentity identity, AuthenticationProperties properties, AccessToken token, JsonElement user) { foreach (var action in Options.ClaimActions) { action.Run(user, identity, ClaimsIssuer); } var context = new TwitterCreatingTicketContext(Context, Scheme, Options, new ClaimsPrincipal(identity), properties, token.UserId, token.ScreenName, token.Token, token.TokenSecret, user); await Events.CreatingTicket(context); return(new AuthenticationTicket(context.Principal, context.Properties, Scheme.Name)); }
protected virtual async Task <AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, AccessToken token) { var context = new TwitterCreatingTicketContext(Context, Options, token.UserId, token.ScreenName, token.Token, token.TokenSecret) { Principal = new ClaimsPrincipal(identity), Properties = properties }; await Options.Events.CreatingTicket(context); if (context.Principal?.Identity == null) { return(null); } return(new AuthenticationTicket(context.Principal, context.Properties, Options.AuthenticationScheme)); }
/// <summary> /// Invoked whenever Twitter successfully authenticates a user /// </summary> /// <param name="context">Contains information about the login session as well as the user <see cref="System.Security.Claims.ClaimsIdentity"/>.</param> /// <returns>A <see cref="Task"/> representing the completed operation.</returns> public virtual Task CreatingTicket(TwitterCreatingTicketContext context) => OnCreatingTicket(context);