Пример #1
0
        protected override void LoadUserAuthInfo(AuthUserSession userSession, IAuthTokens tokens, Dictionary <string, string> authInfo)
        {
            try
            {
                tokens.UserId      = authInfo.Get("id");
                tokens.UserName    = authInfo.Get("id") ?? authInfo.Get("username");
                tokens.DisplayName = authInfo.Get("name");
                tokens.FirstName   = authInfo.Get("first_name");
                tokens.LastName    = authInfo.Get("last_name");
                tokens.Email       = authInfo.Get("email");

                var json    = AuthHttpGateway.DownloadFacebookUserInfo(tokens.AccessTokenSecret, "picture");
                var obj     = JsonObject.Parse(json);
                var picture = obj.Object("picture");
                var data    = picture?.Object("data");
                if (data != null)
                {
                    if (data.TryGetValue("url", out var profileUrl))
                    {
                        tokens.Items[AuthMetadataProvider.ProfileUrlKey] = profileUrl.SanitizeOAuthUrl();
                    }
                }
                userSession.UserAuthName = tokens.Email ?? tokens.UserName;
            }
            catch (Exception ex)
            {
                Log.Error($"Could not retrieve facebook user info for '{tokens.DisplayName}'", ex);
            }

            LoadUserOAuthProvider(userSession, tokens);
        }
Пример #2
0
        protected virtual object AuthenticateWithAccessToken(IServiceBase authService, IAuthSession session, IAuthTokens tokens, string accessToken)
        {
            tokens.AccessTokenSecret = accessToken;

            var json     = AuthHttpGateway.DownloadFacebookUserInfo(accessToken, Fields);
            var authInfo = JsonObject.Parse(json);

            session.IsAuthenticated = true;

            return(OnAuthenticated(authService, session, tokens, authInfo));
        }
Пример #3
0
        protected virtual async Task <object> AuthenticateWithAccessTokenAsync(IServiceBase authService, IAuthSession session, IAuthTokens tokens, string accessToken, CancellationToken token = default)
        {
            tokens.AccessTokenSecret = accessToken;

            var json     = AuthHttpGateway.DownloadFacebookUserInfo(accessToken, Fields);
            var authInfo = JsonObject.Parse(json);

            session.IsAuthenticated = true;

            return(await OnAuthenticatedAsync(authService, session, tokens, authInfo, token).ConfigAwait());
        }
Пример #4
0
        protected override void LoadUserAuthInfo(AuthUserSession userSession, IAuthTokens tokens, System.Collections.Generic.Dictionary <string, string> authInfo)
        {
            try
            {
                var json = AuthHttpGateway.DownloadFacebookUserInfo(tokens.AccessTokenSecret);
                var obj  = JsonObject.Parse(json);
                tokens.UserId      = obj.Get("id");
                tokens.UserName    = obj.Get("username");
                tokens.DisplayName = obj.Get("name");
                tokens.FirstName   = obj.Get("first_name");
                tokens.LastName    = obj.Get("last_name");
                tokens.Email       = obj.Get("email");

                LoadUserOAuthProvider(userSession, tokens);
            }
            catch (Exception ex)
            {
                Log.Error("Could not retrieve facebook user info for '{0}'".Fmt(tokens.DisplayName), ex);
            }
        }
Пример #5
0
        protected override void LoadUserAuthInfo(AuthUserSession userSession, IAuthTokens tokens, System.Collections.Generic.Dictionary <string, string> authInfo)
        {
            try
            {
                var json = AuthHttpGateway.DownloadFacebookUserInfo(tokens.AccessTokenSecret);
                var obj  = JsonObject.Parse(json);
                tokens.UserId      = obj.Get("id");
                tokens.UserName    = obj.Get("username");
                tokens.DisplayName = obj.Get("name");
                tokens.FirstName   = obj.Get("first_name");
                tokens.LastName    = obj.Get("last_name");
                tokens.Email       = obj.Get("email");

                if (SaveExtendedUserInfo)
                {
                    obj.Each(x => authInfo[x.Key] = x.Value);
                }

                json = AuthHttpGateway.DownloadFacebookUserInfo(tokens.AccessTokenSecret, "picture");
                obj  = JsonObject.Parse(json);
                var picture = obj.Object("picture");
                var data    = picture != null?picture.Object("data") : null;

                if (data != null)
                {
                    string profileUrl;
                    if (data.TryGetValue("url", out profileUrl))
                    {
                        tokens.Items[AuthMetadataProvider.ProfileUrlKey] = profileUrl;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Error("Could not retrieve facebook user info for '{0}'".Fmt(tokens.DisplayName), ex);
            }

            LoadUserOAuthProvider(userSession, tokens);
        }