public async Task <ApiResponse <Token> > GetAccessTokenAsync <T>(T credentials, CancellationToken cancellationToken = default(CancellationToken)) where T : IOAuthCredentials { ClientCredentials credentials1 = (object)(T)credentials as ClientCredentials; if (credentials1 != null) { return(await this.GetAccessTokenAsync(credentials1, cancellationToken)); } PasswordCredentials credentials2 = (object)(T)credentials as PasswordCredentials; if (credentials2 != null) { return(await this.GetAccessTokenAsync(credentials2, cancellationToken)); } AuthorizationCodeCredentials credentials3 = (object)(T)credentials as AuthorizationCodeCredentials; if (credentials3 != null) { return(await this.GetAccessTokenAsync(credentials3, cancellationToken)); } RefreshTokenCredentials credentials4 = (object)(T)credentials as RefreshTokenCredentials; if (credentials4 != null) { return(await this.GetAccessTokenAsync(credentials4, cancellationToken)); } throw new AuthenticationException("Unsupported credential type"); }
public ApiResponse <Token> GetAccessToken <T>(T credentials) where T : IOAuthCredentials { ClientCredentials credentials1 = (object)credentials as ClientCredentials; if (credentials1 != null) { return(this.GetAccessToken(credentials1)); } PasswordCredentials credentials2 = (object)credentials as PasswordCredentials; if (credentials2 != null) { return(this.GetAccessToken(credentials2)); } AuthorizationCodeCredentials credentials3 = (object)credentials as AuthorizationCodeCredentials; if (credentials3 != null) { return(this.GetAccessToken(credentials3)); } RefreshTokenCredentials credentials4 = (object)credentials as RefreshTokenCredentials; if (credentials4 != null) { return(this.GetAccessToken(credentials4)); } throw new AuthenticationException("Unsupported credential type"); }
public async Task <string> SetNewPassword(PasswordCredentials request) { using (var dbContext = new TtcDbContext()) { PlayerEntity player; if (request.PlayerId == SystemPlayerIdFromFrontend) { player = await dbContext.Players.SingleAsync(ply => ply.NaamKort == "SYSTEM"); } else { player = await dbContext.Players.SingleOrDefaultAsync(x => x.Id == request.PlayerId); } if (player != null) { await dbContext.Database.ExecuteSqlCommandAsync( $"UPDATE {PlayerEntity.TableName} SET paswoord=MD5({{1}}) WHERE id={{0}}", player.Id, request.NewPassword); return(player.Email); } return(null); } }
/// <summary> /// Create an <see cref="AuthenticationRequest"/> using the specified username and password as credentials. /// </summary> /// <remarks> /// <note type="warning"> /// For improved security, clients are encouraged to use API key credentials instead of a password whenever /// possible. /// </note> /// </remarks> /// <param name="username">The account username.</param> /// <param name="password">The account password.</param> /// <returns> /// <para>An <see cref="AuthenticationRequest"/> instance containing the specified credentials, which is /// typically used for constructing an instance of <see cref="RackspaceAuthenticationService"/>.</para> /// </returns> /// <exception cref="ArgumentNullException"> /// <para>If <paramref name="username"/> is <see langword="null"/>.</para> /// <para>-or-</para> /// <para>If <paramref name="password"/> is <see langword="null"/>.</para> /// </exception> /// <exception cref="ArgumentException"> /// <para>If <paramref name="username"/> is empty.</para> /// <para>-or-</para> /// <para>If <paramref name="password"/> is empty.</para> /// </exception> public static AuthenticationRequest Password(string username, string password) { if (username == null) { throw new ArgumentNullException("username"); } if (password == null) { throw new ArgumentNullException("password"); } if (string.IsNullOrEmpty(username)) { throw new ArgumentException("username cannot be empty"); } if (string.IsNullOrEmpty(password)) { throw new ArgumentException("password cannot be empty"); } PasswordCredentials passwordCredentials = new PasswordCredentials(username, password); AuthenticationData authenticationData = new AuthenticationData(passwordCredentials); AuthenticationRequest authenticationRequest = new AuthenticationRequest(authenticationData); return(authenticationRequest); }
public async Task <User> ChangePassword([FromBody] PasswordCredentials userNewPassword) { var player = await _service.ChangePassword(userNewPassword); if (player != null) { player.Token = TtcAuthorizationFilterAttribute.CreateToken(player); } return(player); }
/// <summary> /// Logs in a registered and certified user to the Yodlee platform. /// </summary> /// <param name="loginName"></param> /// <param name="password"></param> /// <returns></returns> public UserContext loginUser(String loginName, String password) { var passwordCredentials = new PasswordCredentials { loginName = loginName, password = password }; var cobrandContext = GetCobrandContext(); UserInfo1 userInfo1 = loginService.login1(cobrandContext, passwordCredentials, null, false); return(userInfo1 == null ? null : userInfo1.userContext); }
private bool IsTokenRequired() { if (_usePassword || _useAuthorizationCode) { return(true); } _currentOAuthToken = _passwordCredentialsState.Load(); return(_currentOAuthToken.HasExpired()); }
public async Task AdminSetNewPassword([FromBody] PasswordCredentials request) { string playerEmail = await _service.SetNewPassword(request); if (!string.IsNullOrWhiteSpace(playerEmail)) { var emailConfig = await _configService.GetEmailConfig(); var emailer = new PasswordChangedEmailer(emailConfig); emailer.Email(playerEmail); } }
public async Task <string> AuthenticateUserAsync(AuthenticationCredentialsExt credentials) { try { AuthenticationCredentials credentialsIn; if (credentials is PasswordCredentialsExt) { credentialsIn = new PasswordCredentials { Username = credentials.Username, Password = ((PasswordCredentialsExt)credentials).Password }; } else if (credentials is DigitalSignatureCredentialsExt) { credentialsIn = new DigitalSignatureCredentials { Username = credentials.Username, DigitalSignature = Array.ConvertAll(((DigitalSignatureCredentialsExt)credentials).DigitalSignature, b => unchecked ((byte)b)), SignedContent = CombineContentWithSalt(credentials.Username) }; } else if (credentials is OpenIdCredentialsExt openIdCredentials) { //Username is extracted from the access_token later. credentialsIn = new OpenIdCredentials { OpenIdAccessToken = openIdCredentials.OpenIdAccessToken, }; } else { log.Error("Credentials of class " + credentials.GetType().Name + " are not supported. Change the HaaSMiddleware.ServiceTier.UserAndLimitationManagement.UserAndLimitationManagementService.AuthenticateUser() method to add support for additional credential types."); throw new ArgumentException("Credentials of class " + credentials.GetType().Name + " are not supported. Change the HaaSMiddleware.ServiceTier.UserAndLimitationManagement.UserAndLimitationManagementService.AuthenticateUser() method to add support for additional credential types."); } using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork()) { IUserAndLimitationManagementLogic userLogic = LogicFactory.GetLogicFactory().CreateUserAndLimitationManagementLogic(unitOfWork); var result = await userLogic.AuthenticateUserAsync(credentialsIn); return(result); } } catch (Exception exc) { ExceptionHandler.ThrowProperExternalException(exc); return(null); } }
/// <summary> /// Changes the password of a user on the Yodlee platform. /// </summary> /// <param name="userContext"></param> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="changePassword"></param> public void changePassword(UserContext userContext, String userName, String password, String changePassword) { var oldCredentials = new PasswordCredentials { loginName = userName, password = password }; var newCredentials = new PasswordCredentials { loginName = userName, password = changePassword }; loginService.changeCredentials(userContext, oldCredentials, newCredentials); }
/// <summary> /// Logs in a registered and certified user to the Yodlee platform. /// </summary> /// <param name="loginName"></param> /// <param name="password"></param> /// <returns></returns> public UserContext loginUser(String loginName, String password) { PasswordCredentials passwordCredentials = new PasswordCredentials(); passwordCredentials.loginName = loginName; passwordCredentials.password = password; UserInfo1 userInfo1 = null; userInfo1 = loginService.login1(getCobrandContext(), passwordCredentials, null, false); if (userInfo1 == null) { return(null); } else { return(userInfo1.userContext); } }
public async Task <ApiResponse <Token> > GetAccessTokenAsync(PasswordCredentials credentials, CancellationToken cancellationToken = default(CancellationToken)) { return(await this.GetAccessTokenAsync((IDictionary <string, string>) new Dictionary <string, string>() { { "username", credentials.Username }, { "password", credentials.Password }, { "grant_type", credentials.GrantType } }, (string)null, cancellationToken)); }
public ApiResponse <Token> GetAccessToken(PasswordCredentials credentials) { return(this.GetAccessToken((IDictionary <string, string>) new Dictionary <string, string>() { { "username", credentials.Username }, { "password", credentials.Password }, { "grant_type", credentials.GrantType } }, (string)null)); }
/// <summary> /// Changes the password of a user on the Yodlee platform. /// </summary> /// <param name="userContext"></param> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="changePassword"></param> public void changePassword(UserContext userContext, String userName, String password, String changePassword) { PasswordCredentials oldCredentials = new PasswordCredentials(); oldCredentials.loginName = userName; oldCredentials.password = password; PasswordCredentials newCredentials = new PasswordCredentials(); newCredentials.loginName = userName; newCredentials.password = changePassword; loginService.changeCredentials(userContext, oldCredentials, newCredentials); }
public ServiceList AuthenticatePasswordCredentials(PasswordCredentials details) { var client = new RestClient(this.url); var request = new RestRequest("oauth/token", Method.POST) { RequestFormat = DataFormat.Json, JsonSerializer = new RestSharpJsonNetSerializer() }; request.AddBody(details); var response = client.Execute <ResponseToken>(request); if (response.StatusCode != HttpStatusCode.OK) { throw new Exception("Error request"); } return(new ServiceList(this.url, response.Data)); }
//[Test] public void ToProductionEmails() { using (var context = new TtcDbContext()) { var service = new PlayerService(); string strSql = ""; string emails = ""; var spelers = context.Players.Where(x => x.Gestopt == null).ToArray(); foreach (var speler in spelers) { string newPwd = Path.GetRandomFileName(); newPwd = newPwd.Substring(0, newPwd.IndexOf(".")); var newCreds = new PasswordCredentials { PlayerId = speler.Id, NewPassword = newPwd }; strSql += string.Format($"UPDATE {PlayerEntity.TableName} SET paswoord=MD5(\"{{1}}\") WHERE id={{0}};", newCreds.PlayerId, newCreds.NewPassword) + Environment.NewLine; context.Database.ExecuteSqlCommand( $"UPDATE {PlayerEntity.TableName} SET paswoord=MD5({{1}}) WHERE id={{0}}", newCreds.PlayerId, newCreds.NewPassword); //Console.WriteLine(speler.Email + "," + newPwd); emails += speler.Email.Trim() + "," + newPwd + Environment.NewLine; } Console.WriteLine(strSql); Console.WriteLine(emails); } }
private async void OnAuthRequired(object sender, AuthRequiredEventArgs e) { string requestId = e.RequestId; Uri uri = new Uri(e.Uri); bool successfullyAuthenticated = false; foreach (var authenticationHandler in this.authenticationHandlers) { if (authenticationHandler.UriMatcher.Invoke(uri)) { PasswordCredentials credentials = authenticationHandler.Credentials as PasswordCredentials; await this.session.Value.Domains.Network.ContinueWithAuth(e.RequestId, credentials.UserName, credentials.Password); successfullyAuthenticated = true; break; } } if (!successfullyAuthenticated) { await this.session.Value.Domains.Network.CancelAuth(e.RequestId); } }
public async Task <User> ChangePassword(PasswordCredentials userNewCredentials) { using (var dbContext = new TtcDbContext()) { var pwdCheck = await dbContext.Database.SqlQuery <int>( $"SELECT COUNT(0) FROM {PlayerEntity.TableName} WHERE id={{0}} AND paswoord=MD5({{1}})", userNewCredentials.PlayerId, userNewCredentials.OldPassword).FirstOrDefaultAsync(); if (pwdCheck != 1) { return(null); } else { await dbContext.Database.ExecuteSqlCommandAsync( $"UPDATE {PlayerEntity.TableName} SET paswoord=MD5({{1}}) WHERE id={{0}}", userNewCredentials.PlayerId, userNewCredentials.NewPassword); return(await GetUser(userNewCredentials.PlayerId)); } } }
public UserContext registerUser(String loginName, String password, String email) { // Create UserCredentials PasswordCredentials pc = new PasswordCredentials(); pc.loginName = loginName; pc.password = password; // Create UserProfile UserProfile up = new UserProfile(); Entry[] upEntries = new Entry[4]; Entry upEntry1 = new Entry(); upEntry1.key = "EMAIL_ADDRESS"; upEntry1.value = email; Entry upEntry2 = new Entry(); upEntry2.key = "ADDRESS_1"; upEntry2.value = "3600 Bridge Parkway"; Entry upEntry3 = new Entry(); upEntry3.key = "CITY"; upEntry3.value = "Redwood City"; Entry upEntry4 = new Entry(); upEntry4.key = "COUNTRY"; upEntry4.value = "US"; upEntries[0] = upEntry1; upEntries[1] = upEntry2; upEntries[2] = upEntry3; upEntries[3] = upEntry4; up.values = upEntries; NVPair singlePref = null; singlePref = new NVPair(); singlePref.name = "com.yodlee.userprofile.LOCALE"; singlePref.type = 1; object[] obj = new object[1]; obj[0] = (object)"en-US"; singlePref.values = obj; NVPair pincodePref = null; pincodePref = new NVPair(); pincodePref.name = "com.yodlee.userprofile.ZIP_CODE_1"; pincodePref.type = 1; object[] obj1 = new object[1]; obj1[0] = (object)"33444"; pincodePref.values = obj1; NVPair[] nvPairs = new NVPair[2]; nvPairs[0] = singlePref; nvPairs[1] = pincodePref; //System.Console.WriteLine("singlePref " + nvPairs[0].type); //System.Console.WriteLine("singlePref " + nvPairs[1].type); // Register the user UserInfo1 ui = registerService.register3(getCobrandContext(), pc, up, nvPairs); return(ui.userContext); }
public HttpResponseMessage PostAuthenticate([FromBody] AuthenticationRequest authenticationRequest) { MediaTypeHeaderValue acceptedType = new MediaTypeHeaderValue("application/json"); MediaTypeHeaderValue contentType = Request.Content.Headers.ContentType; if (!HttpApiCall.IsAcceptable(acceptedType, contentType)) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } ValidateRequest(Request); if (authenticationRequest == null) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } AuthenticationData authenticationData = authenticationRequest.AuthenticationData; if (authenticationData == null) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } if (authenticationData.TenantName != null && !string.Equals(authenticationData.TenantName, _tenantName, StringComparison.OrdinalIgnoreCase)) { return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); } if (authenticationData.TenantId != null && authenticationData.TenantId != new ProjectId(_tenantId)) { return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); } if (authenticationData.Token != null) { throw new NotImplementedException(); } PasswordCredentials passwordCredentials = authenticationData.PasswordCredentials; if (passwordCredentials == null) { return(new HttpResponseMessage(HttpStatusCode.BadRequest)); } if (!string.Equals(passwordCredentials.Username, _username, StringComparison.OrdinalIgnoreCase) || !string.Equals(passwordCredentials.Password, _password, StringComparison.Ordinal)) { return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); } bool hasTenant = authenticationData.TenantId != null || authenticationData.TenantName != null; string responseBody; if (hasTenant) { responseBody = IdentityServiceResources.AuthenticateResponseTemplate; } else { responseBody = IdentityServiceResources.AuthenticateWithoutTenantResponseTemplate; } lock (_lock) { var parameters = new Dictionary <string, string>(); // expire the token 5 minutes early if (!_tokenExpires.HasValue || _tokenExpires < DateTimeOffset.Now - TimeSpan.FromMinutes(5)) { // generate a new token _tokenCreated = DateTimeOffset.Now; _tokenExpires = _tokenCreated + TimeSpan.FromHours(24); _tokenId = new TokenId(Guid.NewGuid().ToString()); } parameters["issued_at"] = JsonConvert.SerializeObject(_tokenCreated.Value); parameters["expires"] = JsonConvert.SerializeObject(_tokenExpires.Value); parameters["tokenId"] = JsonConvert.SerializeObject(_tokenId); parameters["tenantId"] = JsonConvert.SerializeObject(_tenantId); parameters["tenantName"] = JsonConvert.SerializeObject(_tenantName); parameters["username"] = JsonConvert.SerializeObject(_username); parameters["userId"] = JsonConvert.SerializeObject(_userId); parameters["userFullName"] = JsonConvert.SerializeObject(_userFullName); foreach (var pair in parameters) { responseBody = responseBody.Replace("{" + pair.Key + "}", JsonConvert.DeserializeObject <string>(pair.Value)); } } HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK); result.Content = new StringContent(responseBody, Encoding.UTF8, "application/json"); return(result); }
public bool Save(PasswordCredentials passwordCredentials) { _passwordCredentials = passwordCredentials; return(true); }
public UserContext DoRegisterUser(string loginName, string password, string email) { // These values are hard coded since we don't have them at the time of the registration string country = "US"; string town = "Redwood City"; string address = "3600 Bridge Parkway"; string zipcode = "33444"; // Create UserCredentials var pc = new PasswordCredentials(); pc.loginName = loginName; pc.password = password; // Create UserProfile var up = new UserProfile(); var upEntries = new Entry[4]; var upEntry1 = new Entry(); upEntry1.key = "EMAIL_ADDRESS"; upEntry1.value = email; var upEntry2 = new Entry(); upEntry2.key = "ADDRESS_1"; upEntry2.value = address; var upEntry3 = new Entry(); upEntry3.key = "CITY"; upEntry3.value = town; var upEntry4 = new Entry(); upEntry4.key = "COUNTRY"; upEntry4.value = country; upEntries[0] = upEntry1; upEntries[1] = upEntry2; upEntries[2] = upEntry3; upEntries[3] = upEntry4; up.values = upEntries; var singlePref = new NVPair(); singlePref.name = "com.yodlee.userprofile.LOCALE"; singlePref.type = 1; var obj = new object[1]; obj[0] = (object)"en-US"; singlePref.values = obj; NVPair pincodePref = null; pincodePref = new NVPair(); pincodePref.name = "com.yodlee.userprofile.ZIP_CODE_1"; pincodePref.type = 1; var obj1 = new object[1]; obj1[0] = zipcode; pincodePref.values = obj1; var nvPairs = new NVPair[2]; nvPairs[0] = singlePref; nvPairs[1] = pincodePref; // Register the user UserInfo1 ui = registerService.register3(GetCobrandContext(), pc, up, nvPairs); return(ui.userContext); }
void sessionlessViewItems() { System.Console.Write("Login: "******""; System.Console.Write("Password: "******"SessionLess core calls"); PasswordCredentials passwordCredentials = new PasswordCredentials(); passwordCredentials.loginName = userName; passwordCredentials.password = password; UserContext sessionlessUserContext = new UserContext(); CobrandContext cobrandContext = getCobrandContext(); sessionlessUserContext.cobrandConversationCredentials = cobrandContext.cobrandConversationCredentials; sessionlessUserContext.conversationCredentials = passwordCredentials; sessionlessUserContext.applicationId = cobrandContext.applicationId; sessionlessUserContext.channelId = cobrandContext.channelId; sessionlessUserContext.channelIdSpecified = true; sessionlessUserContext.cobrandId = cobrandContext.cobrandId; sessionlessUserContext.cobrandIdSpecified = true; sessionlessUserContext.ipAddress = cobrandContext.ipAddress; sessionlessUserContext.isPasswordExpired = false; sessionlessUserContext.locale = cobrandContext.locale; sessionlessUserContext.preferenceInfo = cobrandContext.preferenceInfo; sessionlessUserContext.tncVersion = cobrandContext.tncVersion; sessionlessUserContext.tncVersionSpecified = true; sessionlessUserContext.valid = true; sessionlessUserContext.validationHandler = cobrandContext.validationHandler; Object[] itemSummaries = (Object[])dataService.getItemSummaries(sessionlessUserContext); if (itemSummaries == null || itemSummaries.Length == 0) { System.Console.WriteLine("You have no Items Added."); } else { for (int i = 0; i < itemSummaries.Length; i++) { ItemSummary itemSummary = (ItemSummary)itemSummaries[i]; String displayName = itemSummary.contentServiceInfo.contentServiceDisplayName; System.Console.WriteLine("ItemId: " + itemSummary.itemId + " DisplayName: " + displayName + " errorCode: " + itemSummary.refreshInfo.statusCode + " refreshInfo time: " /**new Date(itemSummary.refreshInfo.lastUpdatedTime * 1000)*/); } } }