コード例 #1
0
        public IActionResult Tokens([FromBody] StandardAuthData authData)
        {
            if (authData != null &&
                authData.Password == "password2" &&
                authData.Username == "username2")
            {
                accessTokenRequestCount++;
                lastAccessTokenExpirationDate = DateTime.UtcNow.AddSeconds(accessTokenLifetimeSeconds);
                return(this.Ok(new
                {
                    AccessToken = Guid.NewGuid().ToString(),
                    Expires_in = lastAccessTokenExpirationDate.AddHours(moscowTimezone)
                }));
            }

            return(this.Unauthorized("Wrong credentials"));
        }
コード例 #2
0
        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" });
        }