public IActionResult Refresh([FromBody] RefreshToken authorizationHeader) { var tokenHandler = new JwtSecurityTokenHandler(); var token = tokenHandler.ReadJwtToken(authorizationHeader.Refresh); if (token.ValidTo >= DateTime.UtcNow) { var accessToken = JwtTokenGenerator.Create(DateTime.UtcNow.AddSeconds(accessTokenLifetime), "access"); accessTokenRequestCount++; return this.Ok(new { access = accessToken, }); } return this.Unauthorized(new { Error = "Wrong refresh token" }); }
public IActionResult Tokens([FromForm] Agent2AuthData authData) { if (authData != null && authData.Password == "password3" && authData.Username == "username3" && authData.Field1 == "field1" && authData.Field2 == "field2") { accessTokenRequestCount++; lastAccessTokenExpirationDate = DateTime.UtcNow.AddSeconds(unexpectedAgentTimeShift); return(this.Ok(new { access_token = JwtTokenGenerator.Create(lastAccessTokenExpirationDate.AddHours(6), "access"), expires_in = accessTokenLifetimeSeconds })); } return(this.Unauthorized("Wrong credentials")); }
public IActionResult Tokens([FromBody] StandardAuthData authData) { if (authData != null && authData.Password == "password1" && authData.Username == "username1") { var refreshToken = JwtTokenGenerator.Create(DateTime.UtcNow.AddSeconds(refreshTokenLifetime), "refresh"); lastRefreshToken = refreshToken; refreshTokenRequestCount++; accessTokenRequestCount++; return this.Ok(new { access = JwtTokenGenerator.Create(DateTime.UtcNow.AddSeconds(accessTokenLifetime), "access"), refresh = refreshToken }); } return this.Unauthorized(new { Error = "Wrong credentials" }); }