Skip to content

Commit

Permalink
Fixed error on Basic Authentication that is not created by request
Browse files Browse the repository at this point in the history
  • Loading branch information
andreareginato committed Jan 23, 2013
1 parent 12d17cd commit 202b627
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 15 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog


## v0.1.4 (22 Jan 2013)

* Fixed missing Basic Auth that somehow is not created from the request library

## v0.1.3 (22 Jan 2013)

* Fixed bug on AccessToken#expired() as it had the inverse logic
Expand Down
35 changes: 25 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,38 @@ Install the client library using git:
## Getting started

```javascript
var credentials = { client: { id: 'client-id', secret: 'client-secret', site: 'https://oauth2.com' } };
// Set the client credentials
var credentials = { client: {
id: '<client-id>',
secret: '<client-secret>',
site: 'https://auth.service.com'
}};

// Initialize the OAuth2 Library
var OAuth2 = require('simple-oauth2')(credentials);

// Returns the URI where to redirect your app
var redirect = Oauth2.AuthCode.authorizeURL({ redirectURI: 'http://localhost:3000/callback', scope: 'user', state: '02afe928b');
// => "https://example.org/oauth/authorization?response_type=code&client_id=client_id&redirect_uri=http://localhost:3000/callback&scope=user&state=02afe928b"
// Authorization OAuth2 URI
var authorization_uri = OAuth2.AuthCode.authorizeURL({
redirect_uri: 'http://localhost:3000/callback'
});

// Get the access token object
vat params = { code: 'authorization-code', redirectURI: 'http://localhost:3000/callback' }
OAuth2.AuthCode.getToken(params, function(error, result) {
// save the token
})
// Redirect example using Express (see http://expressjs.com/api.html#res.redirect)
res.redirect(authorization_uri);

// Get the access token object (authorization code is given from previous step)
var token;
OAuth2.AuthCode.getToken({
code: code,
redirect_uri: 'http://localhost:3000/callback'
}, function(error, result) { token = result });

// Create the access token wrapper
var token = OAuth2.AccessToken.create(json_token);
```

## Documentation

Check out the complete [Simple Oauth2 Documentation](http://andreareginato.github.com/simple-oauth2)
Check out the complete [Simple OAuth2 website](http://andreareginato.github.com/simple-oauth2)


## Contributing
Expand Down
2 changes: 1 addition & 1 deletion lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = function(config) {
function call(method, url, params, callback) {

var options = { uri: url, method: method }
if (config.client) options.auth = { 'user': config.client.id, 'pass': config.client.secret }
if (config.client) options.headers = { 'Authorization': 'Basic ' + new Buffer(config.client.id + ':' + config.client.secret).toString('base64') }

if (isEmpty(params)) params = null;
if (method != 'GET') options.form = params;
Expand Down
6 changes: 4 additions & 2 deletions lib/simple-oauth2.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@
//
// // Authorization OAuth2 URI
// var authorization_uri = OAuth2.AuthCode.authorizeURL({
// redirect_uri: 'http://localhost:3000/callback'
// redirect_uri: 'http://localhost:3000/callback',
// scope: scope,
// state: state
// });
//
// // Redirect example using Express
Expand All @@ -49,7 +51,7 @@
// var token;
// OAuth2.AuthCode.getToken({
// code: 'authorization-code',
// redirectURI: 'http://localhost:3000/callback'
// redirect_uri: 'http://localhost:3000/callback'
// }, function(error, result) { token = result });
//
// // Create the access token wrapper
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simple-oauth2",
"version": "0.1.3",
"version": "0.1.4",
"description": "Node.js client for OAuth2",
"author": "Andrea Reginato <[email protected]>",
"homepage": "http://github.com/andreareginato/simple-oauth2",
Expand Down
2 changes: 1 addition & 1 deletion test/auth-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('OAuth2.AuthCode',function() {

beforeEach(function(done) {
var params = { 'code': 'code', 'redirect_uri': 'http://callback.com', 'grant_type': 'authorization_code' };
request = nock('https://example.org:443').post('/oauth/token', qs.stringify(params)).replyWithFile(200, __dirname + '/fixtures/access_token.json');
request = nock('https://example.org').post('/oauth/token', qs.stringify(params)).replyWithFile(200, __dirname + '/fixtures/access_token.json');
done();
})

Expand Down

0 comments on commit 202b627

Please sign in to comment.