Skip to content
This repository has been archived by the owner on Jul 5, 2022. It is now read-only.

Commit

Permalink
fix: expires_in was always 0
Browse files Browse the repository at this point in the history
  • Loading branch information
eliias committed Feb 19, 2016
1 parent f6382ca commit 3b3a459
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
5 changes: 3 additions & 2 deletions src/grant-types/password.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ export default function({
return Promise
.all([accessToken, refreshToken])
.then(tokens => {
const [accessToken, refreshToken] = tokens
res.body = {
access_token: tokens[0][tokenField],
refresh_token: tokens[1][tokenField],
access_token: accessToken[tokenField],
refresh_token: refreshToken[tokenField],
token_type: ACCESS_TOKEN_TYPE_BEARER,
expires_in: moment(accessToken.expires_at).diff(moment(), 'seconds'),
user_id: user.id
Expand Down
7 changes: 4 additions & 3 deletions src/grant-types/refresh-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ export default function({
return Promise
.all([accessToken, refreshToken])
.then(tokens => {
const [accessToken, refreshToken] = tokens
res.body = {
access_token: tokens[0][tokenField],
refresh_token: tokens[1][tokenField],
access_token: accessToken[tokenField],
refresh_token: refreshToken[tokenField],
token_type: ACCESS_TOKEN_TYPE_BEARER,
expires_in: moment(tokens[0].expires_at).diff(moment(), 'seconds'),
expires_in: moment(accessToken.expires_at).diff(moment(), 'seconds'),
user_id: owner.id
}
})
Expand Down
9 changes: 9 additions & 0 deletions test/tokens/refresh-token.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ describe('netiam-contrib', () => {
.expect(200)
.expect('Content-Type', /json/)
.expect(res => {
res.body.should.have.properties([
'access_token',
'refresh_token',
'token_type',
'expires_in',
'user_id'
])
res.body.expires_in.should.be.above(3000)
refreshToken = res.body.refresh_token
})
.end(done)
Expand All @@ -69,6 +77,7 @@ describe('netiam-contrib', () => {
'expires_in',
'user_id'
])
res.body.expires_in.should.be.above(3000)
})
.end(done)
})
Expand Down

0 comments on commit 3b3a459

Please sign in to comment.