CreateAuthenticationSessionFor() публичный статический Метод

public static CreateAuthenticationSessionFor ( Auth0User auth0User, ISession session ) : void
auth0User Auth0User
session ISession
Результат void
        public static IResponseFormatter AuthenticateThisSession(this NancyModule module)
        {
            var code = (string)module.Request.Query["code"];

            var token = Auth0Client.ExchangeCodeForAccessTokenAsync(new ExchangeCodeRequest
            {
                ClientId          = ConfigurationManager.AppSettings["auth0:ClientId"],
                ClientSecret      = ConfigurationManager.AppSettings["auth0:ClientSecret"],
                RedirectUri       = ConfigurationManager.AppSettings["auth0:CallbackUrl"],
                AuthorizationCode = code
            }).ConfigureAwait(false).GetAwaiter().GetResult();

            var userInfo = Auth0Client.GetUserInfoAsync(token.AccessToken).ConfigureAwait(false).GetAwaiter().GetResult();

            var user = new Auth0User
            {
                AccessToken  = token.AccessToken,
                UserToken    = token.IdToken,
                UserId       = userInfo.UserId,
                Name         = userInfo.FullName,
                Nickname     = userInfo.NickName,
                GravatarUrl  = userInfo.Picture,
                Email        = userInfo.Email,
                UserMetadata = userInfo.UserMetadata,
                AppMetadata  = userInfo.AppMetadata
            };

            Auth0Authentication.CreateAuthenticationSessionFor(user, module.Context.Request.Session);

            return(module.Response);
        }
Пример #2
0
        public static IResponseFormatter AuthenticateThisSession(this NancyModule module)
        {
            var code = (string)module.Request.Query["code"];

            var token = Auth0Client.ExchangeAuthorizationCodePerAccessToken(code,
                                                                            ConfigurationManager.AppSettings["auth0:CallbackUrl"]);

            var userInfo = Auth0Client.GetUserInfo(token);

            var user = new Auth0User
            {
                AccessToken = token.AccessToken,
                UserToken   = token.IdToken,
                UserId      = userInfo.UserId,
                Name        = userInfo.Name,
                Nickname    = userInfo.Nickname,
                GravatarUrl = userInfo.Picture,
                Email       = userInfo.Email
            };

            Auth0Authentication.CreateAuthenticationSessionFor(user, module.Context.Request.Session);

            return(module.Response);
        }