项目作者: reneweb

项目描述 :
This is an example of the oAuth resource owner password flow using oauth2orize, express 4 and mongoDB.
高级语言: JavaScript
项目地址: git://github.com/reneweb/oauth2orize_resource_owner_password_example.git
创建时间: 2014-05-15T23:55:03Z
项目社区:https://github.com/reneweb/oauth2orize_resource_owner_password_example

开源协议:MIT License

下载


oauth2orize_resource_owner_password_example

This is an example of the oAuth resource owner password flow using oauth2orize, express 4 and mongoDB.

Installation
  1. git clone https://github.com/reneweb/oauth2orize_resource_owner_password_example.git
  2. npm install
  3. node app.js

Note: You may need to change the database configuration in the db.js file, if mongoDB doesn’t run using the default port or is not running on localhost.

Usage (with cURL)
0 - Create a client

First of all you need to create a client in the clients collection, for example, with the mongo shell. The client should have a clientId, a clientSecret and it should be a trustedClient.
For example:
{“clientId” : “test”, “clientSecret” : “secret”, “trustedClient” : true}

1 - Register a user
  1. curl -v -H "Content-Type: application/json" -X POST <IP>:<PORT>/users -d '{"username": "<username>", "password": "<password>"}'
2 - Get an access token
  1. curl -v -H "Content-Type: application/json" -X POST <IP>:<PORT>/oauth/token -u <clientId>:<clientSecret> -d '{"username": "<username>", "password": "<password>", "grant_type": "password"}'
3 - Access a restricted resource using the access token
  1. curl -X GET <IP>:<PORT>/restricted -v -H "Authorization: Bearer <accessToken>"
4 - Get a new access token using the refresh token
  1. curl -X POST <IP>:<PORT>/oauth/token -u <clientId>:<clientSecret> -v -H "Content-Type: application/json" -d '{"grant_type": "refresh_token", "refresh_token": "<refreshToken>"}'