Skip to content

Commit

Permalink
Updated README
Browse files Browse the repository at this point in the history
  • Loading branch information
andreareginato committed Jan 21, 2013
1 parent 3ae1cc4 commit c8a5361
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 41 deletions.
19 changes: 10 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Lelylan API for Node.js
# Simple OAuth2

Node.js client library for [Oauth2](http://oauth.net/2/)

Expand Down Expand Up @@ -40,7 +40,7 @@ var redirect = Oauth2.AuthCode.authorizeURL({ redirectURI: 'http://localhost:300

// Get the access token object
vat params = { code: 'authorization-code', redirectURI: 'http://localhost:3000/callback' }
client.authCode.getToken(params, function(error, result){
OAuth2.AuthCode.getToken(params, function(error, result) {
// save the token
})
```
Expand All @@ -62,11 +62,11 @@ have helper strategy classes that simplify client use. They are available via th
and #password methods respectively.
// Authorization code flow
var authURL = client.authCode.authorizeURL({ redirect_uri: 'http://localhost:3000/callback');
var token = client.authCode.getToken({ code: 'authorization-code', redirectURI: 'http://localhost:3000/callback' }, callback);
var uri = OAuth2.AuthCode.authorizeURL({ redirect_uri: 'http://localhost:3000/callback');
var token = OAuth2.AuthCode.getToken({ code: 'authorization-code', redirectURI: 'http://localhost:3000/callback' }, callback);
// Password credentials flow
var token = client.password.getToken({ username: 'username', 'password': 'password' }, callback);
var token = OAuth2.Password.getToken({ username: 'username', 'password': 'password' }, callback);
If the functions fails an error object is passed as first argument to the callback.
The body response object is always the last argument.
Expand All @@ -76,13 +76,13 @@ The body response object is always the last argument.
Exceptions are raised when a 4xx or 5xx status code is returned.
```javascript
SimpleOAtuh2.Error
OAtuh2.HTTPError
```
Through the error message attribute you can access the JSON representation.
```javascript
client.authCode.getToken(function(error, token) {
OAuth2.AuthCode.getToken(function(error, token) {
if (error) { console.log(error.message); }
});
```
Expand All @@ -108,8 +108,9 @@ Follow [github](https://github.com/styleguide/) guidelines.
## Feedback
Use the [issue tracker](http://github.com/lelylan/lelylan-node/issues) for bugs.
[Mail](mailto:[email protected]) or [Tweet](http://twitter.com/lelylan) us for any idea that can improve the project.
Use the [issue tracker](http://github.com/andreareginato/simple-oauth2/issues) for bugs.
[Mail](mailto:[email protected]) or [Tweet](http://twitter.com/andreareginato) us
for any idea that can improve the project.
## Links
Expand Down
61 changes: 29 additions & 32 deletions test/access_token.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,49 +33,46 @@ describe.only('OAuth2.AccessToken',function() {
});


describe('#expired',function() {
describe('when not expired', function() {

describe('when not expired', function() {
it('returns false',function() {
token.expired().should.be.true
});
});

it('returns false',function() {
token.expired().should.be.true
});
describe('when expired', function() {

beforeEach(function(done) {
token.token.expires_at = Date.yesterday();
done();
});

it('returns false',function() {
token.expired().should.be.false
});

describe('when expired', function() {
describe('when refreses token', function() {

beforeEach(function(done) {
token.token.expires_at = Date.yesterday();
var params = { 'grant_type': 'refresh_token', refresh_token: 'ec1a59d298' };
request = nock('https://example.org:443').post('/oauth/token', params).replyWithFile(200, __dirname + '/fixtures/access_token.json');
done();
});

it('returns false',function() {
token.expired().should.be.false
});

describe('when refreses token', function() {

beforeEach(function(done) {
var params = { 'grant_type': 'refresh_token', refresh_token: 'ec1a59d298' };
request = nock('https://example.org:443').post('/oauth/token', params).replyWithFile(200, __dirname + '/fixtures/access_token.json');
done();
});

beforeEach(function(done) {
result = null;
token.refresh(function(e, r) {
error = e; result = r; done();
});
beforeEach(function(done) {
result = null;
token.refresh(function(e, r) {
error = e; result = r; done();
});
});

it('makes the HTTP request', function() {
request.isDone();
});
it('makes the HTTP request', function() {
request.isDone();
});

it('returns an access token',function() {
result.should.have.property('access_token');
});
})
});
it('returns a new access token',function() {
result.should.have.property('access_token');
});
})
});
});

0 comments on commit c8a5361

Please sign in to comment.