コード例 #1
0
        public async Task <AccessTokenResponse> TryRefreshAccessToken(string refreshToken)
        {
            var refreshTokenTicket = await _session.Query <RefreshTokenTicket>()
                                     .FirstOrDefaultAsync(x => x.RefreshToken == refreshToken);

            if (refreshTokenTicket == null)
            {
                return(null);
            }
            if (refreshTokenTicket.ExpirationDate < DateTime.UtcNow)
            {
                return(null);
            }

            var user = await _session.Query <User>().FirstOrDefaultAsync(x => x.Id == refreshTokenTicket.UserId);

            if (user == null)
            {
                return(null);
            }

            _session.Eject(refreshTokenTicket);
            return(BuildAccessToken(user));
        }