Last active
June 2, 2016 03:42
-
-
Save nsipplswezey/d5d4dea65408771a443e7e36891d9c38 to your computer and use it in GitHub Desktop.
users and access tokens
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
npm install -g nodal | |
nodal new users-access-tokens | |
cd users-access-tokens | |
nodal g:model --user | |
nodal g:controller --for Users | |
nodal g:model --access_token | |
nodal g:controller --for Access_Tokens | |
nodal db:create | |
nodal db:prepare | |
nodal db:migrate | |
nodal s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ./app/controllers/v1/access_tokens_controller.js | |
module.exports = (function() { | |
'use strict'; | |
const Nodal = require('nodal'); | |
const AccessToken = Nodal.require('app/models/access_token.js'); | |
class V1AccessTokensController extends Nodal.Controller { | |
//We only need to implement create | |
create() { | |
AccessToken.login(this.params, (err, accessToken) => { | |
this.respond(err || accessToken); | |
}); | |
} | |
return V1AccessTokensController; | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
POST localhost:3000/access_tokens username:nsipplswezey | |
{ | |
"meta": { | |
"total": 0, | |
"count": 0, | |
"offset": 0, | |
"error": { | |
"message": "Must supply grant_type" | |
} | |
}, | |
"data": [] | |
} | |
POST localhost:3000/access_tokens username:nsipplswezey grant_type:password | |
{ | |
"meta": { | |
"total": 0, | |
"count": 0, | |
"offset": 0, | |
"error": { | |
"message": "User not found" | |
} | |
}, | |
"data": [] | |
} | |
POST localhost:3000/users username:nsipplswezey email:nsipplswezey@gmail.com password:password | |
{ | |
"meta": { | |
"total": 1, | |
"count": 1, | |
"offset": 0, | |
"error": null | |
}, | |
"data": [ | |
{ | |
"id": 1, | |
"email": "nsipplswezey@gmail.com", | |
"password": "$2a$10$O9rNtf7nR.7dbXpvDle9N.9mdknObIP.gpHAkN0iouAkL3wka1.Vy", | |
"username": "nsipplswezey", | |
"created_at": "2016-05-29T02:35:08.394Z", | |
"updated_at": "2016-05-29T02:35:08.512Z" | |
} | |
] | |
} | |
POST localhost:3000/access_tokens username:nsipplswezey grant_type:password | |
{ | |
"meta": { | |
"total": 0, | |
"count": 0, | |
"offset": 0, | |
"error": { | |
"message": "Invalid credentials" | |
} | |
}, | |
"data": [] | |
} | |
POST localhost:3000/access_tokens username:nsipplswezey grant_type:password password:password | |
{ | |
"meta": { | |
"total": 1, | |
"count": 1, | |
"offset": 0, | |
"error": null | |
}, | |
"data": [ | |
{ | |
"id": 1, | |
"user_id": 1, | |
"access_token": "887e97143e745a45252f4c07aa7e5960", | |
"token_type": "bearer", | |
"expires_at": "2016-06-28T02:38:32.709Z", | |
"ip_address": null, | |
"created_at": "2016-05-29T02:38:32.709Z", | |
"updated_at": "2016-05-29T02:38:32.711Z" | |
} | |
] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment