/// <summary>Loads user authentication information.</summary>
        ///
        /// <param name="userSession">The user session.</param>
        /// <param name="tokens">     The tokens.</param>
        /// <param name="authInfo">   Information describing the authentication.</param>
        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 objs = JsonObject.ParseArray(json);
                    if (objs.Count > 0)
                    {
                        var obj = objs[0];
                        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);
            }
        }
        /// <summary>Loads user authentication information.</summary>
        ///
        /// <param name="userSession">The user session.</param>
        /// <param name="tokens">     The tokens.</param>
        /// <param name="authInfo">   Information describing the authentication.</param>
        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);
            }
        }
Beispiel #3
0
        /// <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);
            }
        }
Beispiel #4
0
        /// <summary>Loads user authentication information.</summary>
        ///
        /// <param name="userSession">The user session.</param>
        /// <param name="tokens">     The tokens.</param>
        /// <param name="authInfo">   Information describing the authentication.</param>
        protected override void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, Dictionary<string, string> authInfo)
        {
            try
            {
                tokens.UserId = authInfo["user_id"];
                tokens.UserName = authInfo["username"];
                tokens.DisplayName = authInfo["name"];
                tokens.FirstName = authInfo["first_name"];
                tokens.LastName = authInfo["last_name"];
                tokens.Email = authInfo["email"];
                userSession.UserAuthName = tokens.Email;

                this.LoadUserOAuthProvider(userSession, tokens);
            }
            catch (Exception ex)
            {
                Log.Error("Could not retrieve Profile 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);
            }
        }
        /// <summary>Loads user authentication information.</summary>
        ///
        /// <param name="userSession">The user session.</param>
        /// <param name="tokens">     The tokens.</param>
        /// <param name="authInfo">   Information describing the authentication.</param>
        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>Loads user authentication information.</summary>
 ///
 /// <param name="userSession">The user session.</param>
 /// <param name="tokens">     The tokens.</param>
 /// <param name="authInfo">   Information describing the authentication.</param>
 protected virtual void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, Dictionary <string, string> authInfo)
 {
 }
        /// <summary>Loads user authentication information.</summary>
        ///
        /// <param name="userSession">The user session.</param>
        /// <param name="tokens">     The tokens.</param>
        /// <param name="authInfo">   Information describing the authentication.</param>
        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("name"))
                tokens.DisplayName = authInfo.GetValueOrDefault("name");

            if (authInfo.ContainsKey("FullName"))
            {
                tokens.FullName = authInfo.GetValueOrDefault("FullName");
                if (tokens.DisplayName.IsNullOrEmpty())
                    tokens.DisplayName = tokens.FullName;
            }

            if (authInfo.ContainsKey("Email"))
                tokens.Email = authInfo.GetValueOrDefault("Email");

            if (authInfo.ContainsKey("BirthDate"))
                tokens.BirthDate = authInfo.GetValueOrDefault("BirthDate").FromJsv<DateTime?>();

            if (authInfo.ContainsKey("BirthDateRaw"))
                tokens.BirthDateRaw = authInfo.GetValueOrDefault("BirthDateRaw");

            if (authInfo.ContainsKey("Country"))
                tokens.Country = authInfo.GetValueOrDefault("Country");

            if (authInfo.ContainsKey("Culture"))
                tokens.Culture = authInfo.GetValueOrDefault("Culture");

            if (authInfo.ContainsKey("Gender"))
                tokens.Gender = authInfo.GetValueOrDefault("Gender");

            if (authInfo.ContainsKey("MailAddress"))
                tokens.MailAddress = authInfo.GetValueOrDefault("MailAddress");

            if (authInfo.ContainsKey("Nickname"))
                tokens.Nickname = authInfo.GetValueOrDefault("Nickname");

            if (authInfo.ContainsKey("PostalCode"))
                tokens.PostalCode = authInfo.GetValueOrDefault("PostalCode");

            if (authInfo.ContainsKey("TimeZone"))
                tokens.TimeZone = authInfo.GetValueOrDefault("TimeZone");

            LoadUserOAuthProvider(userSession, tokens);
        }
        /// <summary>Login with facebook.</summary>
        ///
        /// <param name="oAuthUserSession">The authentication user session.</param>
		protected void LoginWithFacebook(AuthUserSession oAuthUserSession)
		{
			MockAuthHttpGateway.Tokens = facebookGatewayTokens;
			var facebookAuth = GetFacebookAuthProvider();
			facebookAuth.OnAuthenticated(service, oAuthUserSession, facebookAuthTokens, new Dictionary<string, string>());
			Console.WriteLine("UserId: " + oAuthUserSession.UserAuthId);
		}
        /// <summary>Gets new session 2.</summary>
        ///
        /// <returns>The new session 2.</returns>
		public static AuthUserSession GetNewSession2()
		{
			var oAuthUserSession = new AuthUserSession();
			return oAuthUserSession;
		}
        /// <summary>Registers this object.</summary>
        ///
        /// <param name="userAuthRepository">The user authentication repository.</param>
        /// <param name="oAuthUserSession">  The authentication user session.</param>
        /// <param name="registration">      The registration.</param>
        ///
        /// <returns>An object.</returns>
		protected object Register(IUserAuthRepository userAuthRepository, AuthUserSession oAuthUserSession, Registration registration = null)
		{
			if (registration == null)
				registration = registrationDto;

			var registrationService = GetRegistrationService(userAuthRepository, oAuthUserSession, requestContext);
			var response = registrationService.Post(registration);
			Assert.That(response as IHttpError, Is.Null);
			return response;
		}
        /// <summary>Login.</summary>
        ///
        /// <param name="userName">        Name of the user.</param>
        /// <param name="password">        The password.</param>
        /// <param name="oAuthUserSession">The authentication user session.</param>
        ///
        /// <returns>An object.</returns>
		protected object Login(string userName, string password, AuthUserSession oAuthUserSession = null)
		{
			if (oAuthUserSession == null)
				oAuthUserSession = requestContext.ReloadSession();

			var credentialsAuth = GetCredentialsAuthConfig();
			return credentialsAuth.Authenticate(service, oAuthUserSession,
				new Auth {
					provider = CredentialsAuthProvider.Name,
					UserName = registrationDto.UserName,
					Password = registrationDto.Password,
				});
		}
        /// <summary>Registers the and login.</summary>
        ///
        /// <param name="userAuthRepository">The user authentication repository.</param>
        /// <param name="oAuthUserSession">  The authentication user session.</param>
        ///
        /// <returns>An AuthUserSession.</returns>
		protected AuthUserSession RegisterAndLogin(IUserAuthRepository userAuthRepository, AuthUserSession oAuthUserSession)
		{
			Register(userAuthRepository, oAuthUserSession);

			Login(registrationDto.UserName, registrationDto.Password, oAuthUserSession);

			oAuthUserSession = requestContext.ReloadSession();
			return oAuthUserSession;
		}
        /// <summary>Gets registration service.</summary>
        ///
        /// <param name="userAuthRepository">The user authentication repository.</param>
        /// <param name="oAuthUserSession">  The authentication user session.</param>
        /// <param name="requestContext">    Context for the request.</param>
        ///
        /// <returns>The registration service.</returns>
		public static RegistrationService GetRegistrationService(
			IUserAuthRepository userAuthRepository,
			AuthUserSession oAuthUserSession = null,
			MockRequestContext requestContext = null)
		{
			if (requestContext == null)
				requestContext = new MockRequestContext();
			if (oAuthUserSession == null)
				oAuthUserSession = requestContext.ReloadSession();

			var httpReq = requestContext.Get<IHttpRequest>();
			var httpRes = requestContext.Get<IHttpResponse>();
			oAuthUserSession.Id = httpRes.CreateSessionId(httpReq);
			httpReq.Items[ServiceExtensions.RequestItemsSessionKey] = oAuthUserSession;

			var mockAppHost = new BasicAppHost {
				Container = requestContext.Container
			};

			requestContext.Container.Register(userAuthRepository);

		    var authService = new AuthService {
                RequestContext = requestContext,
            };
            authService.SetResolver(mockAppHost);
            mockAppHost.Register(authService);

			var registrationService = new RegistrationService {
				UserAuthRepo = userAuthRepository,
				RequestContext = requestContext,
				RegistrationValidator =
					new RegistrationValidator { UserAuthRepo = RegistrationServiceTests.GetStubRepo() },
			};
			registrationService.SetResolver(mockAppHost);

			return registrationService;
		}
Beispiel #15
0
 /// <summary>Loads user authentication information.</summary>
 ///
 /// <param name="userSession">The user session.</param>
 /// <param name="tokens">     The tokens.</param>
 /// <param name="authInfo">   Information describing the authentication.</param>
 protected virtual void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, Dictionary<string, string> authInfo) { }