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); } }
public static AuthUserSession GetSession() { new RedisClient().FlushAll(); var oAuthUserSession = new AuthUserSession { AuthHttpGateway = new MockAuthHttpGateway(), }; return oAuthUserSession; }
protected override void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, Dictionary<string, string> authInfo) { var user = Repository.RepoUsers.GetUserByUserNameOrEmail(userSession.UserAuthName, userSession.UserAuthName); userSession.Email = user.Email; userSession.UserName = user.UserName; base.LoadUserAuthInfo(userSession, tokens, authInfo); }
public static void LoadUserAuth(this IRepository repository, AuthUserSession userSession, IOAuthTokens tokens) { userSession.DisplayName = tokens.DisplayName; userSession.FullName = tokens.FullName; userSession.Email = tokens.Email; userSession.UserName = tokens.Email; var user = repository.RepoUsers.GetUserByEmail(tokens.Email); if (user == null || !user.HasOpenId(tokens.UserId)) return; userSession.Roles = user.Roles.FromJsonString<List<string>>(); }
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); } }
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); } }
protected override void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, Dictionary<string, string> authInfo) { var claims = StsConfigSection.Settings.Claims; tokens.UserId = authInfo[claims["id"].ClaimUri]; tokens.UserName = authInfo[claims["username"].ClaimUri]; tokens.FirstName = authInfo[claims["first_name"].ClaimUri]; tokens.LastName = authInfo[claims["last_name"].ClaimUri]; tokens.Email = authInfo[claims["email"].ClaimUri]; tokens.DisplayName = !string.IsNullOrWhiteSpace(tokens.FirstName) && !string.IsNullOrWhiteSpace(tokens.LastName) ? string.Format("{0} {1}", tokens.FirstName, tokens.LastName) : authInfo[claims["name"].ClaimUri]; LoadUserOAuthProvider(userSession, tokens); }
public static AuthUserSession GetNewSession2() { var oAuthUserSession = new AuthUserSession(); return oAuthUserSession; }
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); }
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; }
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, }); }
protected override void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, System.Collections.Generic.Dictionary<string, string> authInfo) { base.LoadUserAuthInfo(userSession, tokens, authInfo); }
protected virtual void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, Dictionary<string, string> authInfo) { }
public static void AddPlugins(List<IPlugin> plugins) { AppSettings appSettings = new AppSettings(); SSAuthInterfaces.AuthUserSession authUserSession = new SSAuthInterfaces.AuthUserSession(); AuthProvider authProvider = new AuthProvider(); SSAuthInterfaces.IAuthProvider[] authProviders = new SSAuthInterfaces.IAuthProvider[] { authProvider }; RequestLogsFeature requestLogsFeature = new RequestLogsFeature(); requestLogsFeature.RequiredRoles = new string[] { }; plugins.Add(new AuthFeature(() => authUserSession, authProviders) { }); plugins.Add(requestLogsFeature); plugins.Add(new RegistrationFeature()); plugins.Add(new ValidationFeature()); }
protected virtual void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, Dictionary <string, string> authInfo) { }
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); } }
protected override void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, System.Collections.Generic.Dictionary<string, string> authInfo) { try { var tokenRequest = WebRequest.Create(this.UserInfoUrl + "?access_token=" + tokens.AccessTokenSecret); var tokenResponse = (HttpWebResponse)tokenRequest.GetResponse(); if (tokenResponse.StatusCode == HttpStatusCode.OK) { using (var reader = new StreamReader(tokenResponse.GetResponseStream())) { var obj = JsonObject.Parse(reader.ReadToEnd()); // Map all standard attributes if present userSession.Id = obj.Get("user_id"); userSession.UserName = obj.Get("nickname"); userSession.DisplayName = obj.Get("name"); userSession.FirstName = obj.Get("given_name"); userSession.LastName = obj.Get("family_name"); userSession.Email = obj.Get("email"); userSession.Gender = obj.Get("gender"); // Map any "groups" to "roles" if (obj.Keys.Contains("groups")) { var groups = obj.Get<string[]>("groups"); userSession.Roles = new List<string>(); userSession.Roles.AddRange(groups); } // Load all properties from Auth0 User Profile into the Dictionary var auth0Session = userSession as Auth0UserSession; if (auth0Session != null) { // Skip complex proprties: 'identitites' and 'emails' string[] skipProperties = { "identities", "emails" }; obj.Keys.Where(k => !skipProperties.Contains(k)).ToList() .ForEach(k => auth0Session.ExtraData[k] = obj.Get(k)); } this.LoadUserOAuthProvider(userSession, tokens); } } } catch (Exception ex) { Log.Error("Could not retrieve auth0 user info for '{0}'".Fmt(tokens.DisplayName), ex); } }
protected override void LoadUserAuthInfo(AuthUserSession userSession, IOAuthTokens tokens, Dictionary<string, string> authInfo) { base.LoadUserAuthInfo(userSession, tokens, authInfo); Repository.LoadUserAuth(userSession, tokens); }
public static AuthUserSession GetNewSession2() { new RedisClient().FlushAll(); var oAuthUserSession = new AuthUserSession(); return oAuthUserSession; }
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.SetAppHost(mockAppHost); mockAppHost.Register(authService); var registrationService = new RegistrationService { UserAuthRepo = userAuthRepository, RequestContext = requestContext, RegistrationValidator = new RegistrationValidator { UserAuthRepo = RegistrationServiceTests.GetStubRepo() }, }; registrationService.SetAppHost(mockAppHost); return registrationService; }
protected AuthUserSession RegisterAndLogin(IUserAuthRepository userAuthRepository, AuthUserSession oAuthUserSession) { Register(userAuthRepository, oAuthUserSession); Login(registrationDto.UserName, registrationDto.Password, oAuthUserSession); oAuthUserSession = requestContext.ReloadSession(); return oAuthUserSession; }
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); }
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 registrationService = new RegistrationService { UserAuthRepo = userAuthRepository, RequestContext = requestContext, RegistrationValidator = new RegistrationValidator { UserAuthRepo = RegistrationServiceTests.GetStubRepo() }, }; return registrationService; }