예제 #1
0
        protected override void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, Dictionary <string, string> authInfo)
        {
            if (authInfo.ContainsKey("user_id"))
            {
                tokens.UserId = authInfo.GetValueOrDefault("user_id");
            }

            if (authInfo.ContainsKey("screen_name"))
            {
                tokens.UserName = authInfo.GetValueOrDefault("screen_name");
            }

            try
            {
                if (tokens.UserId != null)
                {
                    var json = AuthHttpGateway.DownloadTwitterUserInfo(tokens.UserId);
                    var obj  = JsonObject.Parse(json);
                    tokens.DisplayName = obj.Get("name");
                }

                LoadUserOAuthProvider(userSession, tokens);
            }
            catch (Exception ex)
            {
                Log.Error("Could not retrieve twitter user info for '{0}'".Fmt(userSession.TwitterUserId), ex);
            }
        }
예제 #2
0
        protected override void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens 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);
            }
        }
        /// <summary>
        /// Load the UserAuth info into the session.
        /// </summary>
        /// <param name="userSession">
        /// The User session.
        /// </param>
        /// <param name="tokens">
        /// The OAuth tokens.
        /// </param>
        /// <param name="authInfo">
        /// The auth info.
        /// </param>
        protected override void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, Dictionary <string, string> authInfo)
        {
            try
            {
                var contents = AuthHttpGateway.DownloadYammerUserInfo(tokens.UserId);

                var authObj = JsonObject.Parse(contents);

                tokens.UserId      = authObj.Get("id");
                tokens.UserName    = authObj.Get("name");
                tokens.DisplayName = authObj.Get("full_name");
                tokens.FullName    = authObj.Get("full_name");
                tokens.FirstName   = authObj.Get("first_name");
                tokens.LastName    = authObj.Get("last_name");

                var emails = authObj.Object("contact").ArrayObjects("email_addresses").ConvertAll(x =>
                                                                                                  new EmailAddresses
                {
                    Type    = x.Get("type"),
                    Address = x.Get("address")
                });

                var email = emails.FirstOrDefault(q => q.Type == "primary");
                if (email != null)
                {
                    tokens.Email = email.Address;
                }

                // Pass along
                this.LoadUserOAuthProvider(userSession, tokens);
            }
            catch (Exception ex)
            {
                Log.Error("Could not retrieve Yammer user info for '{0}'".Fmt(tokens.DisplayName), ex);
            }
        }
예제 #4
0
        public virtual void OnAuthenticated(IServiceBase oAuthService, IOAuthTokens tokens, Dictionary <string, string> authInfo)
        {
            var provider     = tokens.Provider;
            var authProvider = oAuthService.TryResolve <IUserAuthRepository>();

            if (authProvider != null)
            {
                authProvider.LoadUserAuth(this, tokens);
            }

            if (provider == TwitterAuthConfig.Name)
            {
                if (authInfo.ContainsKey("user_id"))
                {
                    tokens.UserId = this.TwitterUserId = authInfo.GetValueOrDefault("user_id");
                }

                if (authInfo.ContainsKey("screen_name"))
                {
                    tokens.UserName = this.TwitterScreenName = authInfo.GetValueOrDefault("screen_name");
                }

                try
                {
                    var json = AuthHttpGateway.DownloadTwitterUserInfo(this.TwitterUserId);
                    var obj  = JsonObject.Parse(json);
                    tokens.DisplayName = obj.Get("name");
                    this.DisplayName   = tokens.DisplayName ?? this.DisplayName;
                }
                catch (Exception ex)
                {
                    Log.Error("Could not retrieve twitter user info for '{0}'".Fmt(TwitterUserId), ex);
                }
            }
            else if (provider == FacebookAuthConfig.Name)
            {
                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");

                    this.FacebookUserId   = tokens.UserId ?? this.FacebookUserId;
                    this.FacebookUserName = tokens.UserName ?? this.FacebookUserName;
                    this.DisplayName      = tokens.DisplayName ?? this.DisplayName;
                    this.FirstName        = tokens.FirstName ?? this.FirstName;
                    this.LastName         = tokens.LastName ?? this.LastName;
                    this.Email            = tokens.Email ?? this.Email;
                }
                catch (Exception ex)
                {
                    Log.Error("Could not retrieve facebook user info for '{0}'".Fmt(tokens.DisplayName), ex);
                }
            }

            authInfo.ForEach((x, y) => tokens.Items[x] = y);

            SaveUserAuth(oAuthService.TryResolve <IUserAuthRepository>(), tokens);
            OnSaveUserAuth(oAuthService, this.UserAuthId);
        }