public UserControllerFixtureBuilder AddInvalidAuthentication(AuthenticateParameters authParams) { _mockUserService.Setup(userService => userService.Authenticate(authParams)) .Returns((AuthenticatedUser)null); return(this); }
public async Task <IAuthenticateResult> Authenticate(AuthenticateParameters authenticateParameters) { var(clientId, redirectUri, code, refreshToken) = authenticateParameters; GetTokenResponse?response; if (!string.IsNullOrWhiteSpace(refreshToken)) { var formData = new Dictionary <string, string?> { { "grant_type", "refresh_token" }, { "client_id", clientId }, { "client_secret", settings.HubSpot?.ClientSecret }, { "redirect_uri", redirectUri }, { "refresh_token", refreshToken }, }; var request = await httpClient.PostAsync("https://api.hubapi.com/oauth/v1/token", new FormUrlEncodedContent(formData)); response = await request.Content.ReadAsAsync <GetTokenResponse>(); hubSpotApiCache.CodeTokenCache.TryAdd(code, response); } if (!hubSpotApiCache.CodeTokenCache.TryGetValue(code, out response)) { var formData = new Dictionary <string, string?> { { "grant_type", "authorization_code" }, { "client_id", clientId }, { "client_secret", settings.HubSpot?.ClientSecret }, { "redirect_uri", redirectUri }, { "code", code }, }; var request = await httpClient.PostAsync("https://api.hubapi.com/oauth/v1/token", new FormUrlEncodedContent(formData)); if (request.StatusCode == System.Net.HttpStatusCode.BadRequest) { return(new NotAuthenticatedResult()); } response = await request.Content.ReadAsAsync <GetTokenResponse>(); hubSpotApiCache.CodeTokenCache.TryAdd(code, response); } if (response != null) { httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", response.Access_token); return(new AuthenticatedResult { RefreshToken = response.Refresh_token }); } throw new NotImplementedException(); }
public async Task <AuthenticateResult> Authenticate(AuthenticateParameters parameters) { var paramsDictionary = new Dictionary <string, string> { { "username", parameters.UserName }, { "password", parameters.Password } }; return(await ExecuteRequestAsync <AuthenticateResult, AuthenticateOutput>(AuthenticateUrl, HttpMethod.Get, paramsDictionary)); }
private void InitializeDedimaniaClient() { AuthenticateParameters authParams = new AuthenticateParameters { Game = Context.ServerInfo.Version.GetShortName(), Login = Context.ServerInfo.ServerLogin, Packmask = Context.ServerInfo.ServerPackMask, Nation = Context.ServerInfo.ServerNation, Password = Context.ServerInfo.ServerLoginPassword, Tool = TOOL_NAME, Version = Version.ToString(2) }; // set default timeout of dedimania requests to 10 seconds DedimaniaClient = new DedimaniaClient(Settings.AuthUrl, authParams) { Timeout = 10000 }; }
public IAuthenticatedUser Authenticate(AuthenticateParameters authParams) { var user = _userBusiness.AuthenticateUser(authParams.Login, authParams.Password); if (user != null) { var issuedAt = _clock.UtcNow; var jwtToken = _jwtOptions.Enabled ? new JwtSecurityToken( issuer: _jwtOptions.Issuer, claims: user.GetJwtClaims(issuedAt), expires: issuedAt.LocalDateTime.Add(_jwtOptions.Duration), signingCredentials: new SigningCredentials(new SymmetricSecurityKey(_jwtOptions.Key.ToBytes()), SecurityAlgorithms.HmacSha256)) : null; return(AuthenticatedUser.Create(user, jwtToken == null ? null : new JwtSecurityTokenHandler().WriteToken(jwtToken))); } return(null); }
public Task <AuthenticateResult> PostAuthenticate(AuthenticateParameters parameters) { //TODO: something wrong with PostAuthenticate on the server-side throw new NotImplementedException(); }
public ClaimsPrincipal SignIn(AuthenticateParameters authParams, string scheme) { var user = _userBusiness.AuthenticateUser(authParams.Login, authParams.Password); return(user == null ? null : user.GetClaimsPrincipal(scheme)); }
public Task <AuthenticateResult> PostAuthenticate(AuthenticateParameters parameters) { //TODO: something wrong with PostAuthenticate on the server-side //The exception message is 'Object reference not set to an instance of an object.' throw new NotImplementedException(); }