1 | # Simple OAuth2
|
2 |
|
3 | Node.js client library for [Oauth2](http://oauth.net/2/).
|
4 | Currently it supports Authorization Code and Resource Owner Password Credentials grant types.
|
5 |
|
6 |
|
7 | ## Requirements
|
8 |
|
9 | Node client library is tested against Node ~0.8.x
|
10 |
|
11 |
|
12 | ## Installation
|
13 |
|
14 | Install the client library using [npm](http://npmjs.org/):
|
15 |
|
16 | $ npm install simple-oath2
|
17 |
|
18 | Install the client library using git:
|
19 |
|
20 | $ git clone git://github.com/andrearegianto/simple-oauth2.git
|
21 | $ cd simple-oauth2
|
22 | $ npm install
|
23 |
|
24 |
|
25 | ## Getting started
|
26 |
|
27 | ```javascript
|
28 | // Set the client credentials
|
29 | var credentials = { client: {
|
30 | id: '<client-id>',
|
31 | secret: '<client-secret>',
|
32 | site: 'https://auth.service.com'
|
33 | }};
|
34 |
|
35 | // Initialize the OAuth2 Library
|
36 | var OAuth2 = require('simple-oauth2')(credentials);
|
37 |
|
38 | // Authorization OAuth2 URI
|
39 | var authorization_uri = OAuth2.AuthCode.authorizeURL({
|
40 | redirect_uri: 'http://localhost:3000/callback'
|
41 | });
|
42 |
|
43 | // Redirect example using Express (see http://expressjs.com/api.html#res.redirect)
|
44 | res.redirect(authorization_uri);
|
45 |
|
46 | // Get the access token object (authorization code is given from previous step)
|
47 | var token;
|
48 | OAuth2.AuthCode.getToken({
|
49 | code: code,
|
50 | redirect_uri: 'http://localhost:3000/callback'
|
51 | }, function(error, result) { token = result });
|
52 |
|
53 | // Create the access token wrapper
|
54 | var token = OAuth2.AccessToken.create(json_token);
|
55 | ```
|
56 |
|
57 | ## Documentation
|
58 |
|
59 | Check out the complete [Simple OAuth2 website](http://andreareginato.github.com/simple-oauth2)
|
60 |
|
61 |
|
62 | ## Contributing
|
63 |
|
64 | Fork the repo on github and send a pull requests with topic branches. Do not forget to
|
65 | provide specs to your contribution.
|
66 |
|
67 |
|
68 | ### Running specs
|
69 |
|
70 | * Fork and clone the repository (`dev` branch).
|
71 | * Run `npm install` for dependencies.
|
72 | * Run `make test` to execute all specs.
|
73 | * Run `make test-watch` to auto execute all specs when a file change.
|
74 |
|
75 |
|
76 | ## Coding guidelines
|
77 |
|
78 | Follow [github](https://github.com/styleguide/) guidelines.
|
79 |
|
80 |
|
81 | ## Feedback
|
82 |
|
83 | Use the [issue tracker](http://github.com/andreareginato/simple-oauth2/issues) for bugs.
|
84 | [Mail](mailto:andrea.reginato@.gmail.com) or [Tweet](http://twitter.com/andreareginato) us
|
85 | for any idea that can improve the project.
|
86 |
|
87 |
|
88 | ## Links
|
89 |
|
90 | * [GIT Repository](http://github.com/andreareginato/simple-oauth2)
|
91 | * [Documentation](http://andreareginato.github.com/simple-oauth2)
|
92 |
|
93 |
|
94 | ## Authors
|
95 |
|
96 | [Andrea Reginato](http://twitter.com/andreareginato)
|
97 |
|
98 |
|
99 | ## Contributors
|
100 |
|
101 | Special thanks to the following people for submitting patches.
|
102 |
|
103 |
|
104 | ## Changelog
|
105 |
|
106 | See [CHANGELOG](simple-oauth2/blob/master/CHANGELOG.md)
|
107 |
|
108 |
|
109 | ## Copyright
|
110 |
|
111 | Copyright (c) 2013 [Lelylan](http://lelylan.com). See [LICENSE](simple-oauth2/blob/master/LICENSE.md) for details.
|