UNPKG

2.63 kBMarkdownView Raw
1# Simple OAuth2
2
3Node.js client library for [Oauth2](http://oauth.net/2/).
4Currently it supports Authorization Code and Resource Owner Password Credentials grant types.
5
6
7## Requirements
8
9Node client library is tested against Node ~0.8.x
10
11
12## Installation
13
14Install the client library using [npm](http://npmjs.org/):
15
16 $ npm install simple-oath2
17
18Install 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
29var credentials = { client: {
30 id: '<client-id>',
31 secret: '<client-secret>',
32 site: 'https://auth.service.com'
33}};
34
35// Initialize the OAuth2 Library
36var OAuth2 = require('simple-oauth2')(credentials);
37
38// Authorization OAuth2 URI
39var 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)
44res.redirect(authorization_uri);
45
46// Get the access token object (authorization code is given from previous step)
47var token;
48OAuth2.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
54var token = OAuth2.AccessToken.create(json_token);
55```
56
57## Documentation
58
59Check out the complete [Simple OAuth2 website](http://andreareginato.github.com/simple-oauth2)
60
61
62## Contributing
63
64Fork the repo on github and send a pull requests with topic branches. Do not forget to
65provide 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
78Follow [github](https://github.com/styleguide/) guidelines.
79
80
81## Feedback
82
83Use 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
85for 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
101Special thanks to the following people for submitting patches.
102
103
104## Changelog
105
106See [CHANGELOG](simple-oauth2/blob/master/CHANGELOG.md)
107
108
109## Copyright
110
111Copyright (c) 2013 [Lelylan](http://lelylan.com). See [LICENSE](simple-oauth2/blob/master/LICENSE.md) for details.