a sails project with oauth2 integration
a Sails application
###Section A. Basic Test
-
In terminal, run
sails lift
-
In your browser, go to
http://localhost:1337/users
-
If you see the message
Unauthorized
, then you have succeeded.
###Section B. Advanced Test
-
Launch Server
- In terminal, run:
sails lift
-
Register a “Client”
-
Ensure that the custom settings are completed
- Security Config (Step 5) contains valid GMail credentials
- Connections Config (Step 9) contains valid Mongo server details
-
Using Postman, post to
http://localhost:1337/clients/register
withx-www-form-urlencoded
key:value pairs:email : <your email>
where
<your email>
is your actual email (without the < >s). -
You should receive a response as such:
{ "url": "http://localhost:1337/clients/verify/<your email>?code=gqjH6igH6Z89ROEoVRFmEiVYuEfEZ1kQ" }
-
Provided you set the correct credentials in step 5.ii you should now receive an email that reads as such:
Hello! Please visit the verification link to complete the registration process. Account with Client ID : <received client id> Verification Link
-
You can click the verification link now. The resulting page in your browser should read as such:
{ "verified": true, "email": "<your email>" }
-
-
Register a User
-
Using Postman, post to
http://localhost:1337/users/register
withx-www-form-urlencoded
key:value pairs:username : <your username> password : <your password> email : <your email>
Filling out the credentials as appropriate (without the < >s).
-
You should receive a response as such:
{ "url": "http://localhost:1337/users/verify/<your email>?code=Y087VfF3bbHmNrQaRsAfOB8srfNB0gDW" }
-
You should now receive an email that reads as such:
Hello! Please visit the verification link to complete the registration process. Account with Username : <your username> Verification Link
-
You can click the verification link now. The resulting page in your browser should read as such:
{ "verified": true, "email": "<your email>" }
-
-
Request Token
-
In order to request a token, you require a registered client and a registered user (see above).
-
Using Postman, post to
http://localhost:1337/oauth/token
withx-www-form-urlencoded
key:value pairs:grant_type : password client_id : <received client id> username : <your username> password : <your password>
Filling out the credentials as appropriate, but leaving the grant_type as “password”.
-
Make note of the access_token value (
<received access token>
). You should receive a response as such:{ "access_token": "<received access token>", "refresh_token": "<received refresh token>", "expires_in": 3600, "token_type": "Bearer" }
-
-
Request Resource with Token
-
Using Postman, request with GET
http://localhost:1337/users/current
with custom authorization header key:value pair:Authorization : Bearer <received access token>
Replacing the
<received access token>
value with the one you received. -
You should receive a response similar to:
{ "identity": { "username": "<your username>", "email": "<your email>" } }
-