コード例 #1
0
        /// <summary>
        /// OAuth 'OnCreatingTicket' Handler
        /// Executed upon a successful external login.
        /// </summary>
        public static async Task HandleCreatingTicket(OAuthCreatingTicketContext context, GetClaimsCallback getClaimsCallback = null)
        {
            var oauthUser = await context.GetUser <TOAuthUser>();

            var logger             = context.Get <ILogger <TOAuthUser> >();
            var metadataConductor  = context.Get <IRepositoryConductor <TUserMetadata> >();
            var userConductor      = context.Get <IRepositoryConductor <TUser> >();
            var userLoginConductor = context.Get <IRepositoryConductor <TUserLogin> >();

            logger.LogInformation($"Authentication request for {oauthUser.UserMetadataName} {nameof(TUser)} '{oauthUser.Id}' - {oauthUser.Email}");

            var user      = FindOrCreateUser(oauthUser, userConductor, metadataConductor, logger);
            var userLogin = CreateLogin(userLoginConductor, user, context.Request, logger);

            if (getClaimsCallback != null)
            {
                context.Identity.AddClaims(getClaimsCallback(user, userLogin));
            }

            context.RunClaimActions();
        }