Skip to content

Commit

Permalink
Merge pull request #46 from graviton/45-scopes-parameter-fix
Browse files Browse the repository at this point in the history
fix(scope-parameter): fix scopes bug and cleanup
  • Loading branch information
bzums committed Jul 21, 2016
2 parents 9f7c66d + 4b1c045 commit 97f0e4f
Show file tree
Hide file tree
Showing 13 changed files with 22 additions and 39 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ See [STUPS documentation](http://stups.readthedocs.org/en/latest/user-guide/acce

## Usage

Note: `node >= 6.0.0` required to consume this library.

Run `npm install --save git+ssh://[email protected]:graviton/lib-oauth-tooling.git#TAG/COMMIT` where `TAG/COMMIT` has to be replaced with the release tag or commit id you want to use.
Import a member of this lib like so (of course ES5 syntax is working as well...):

Expand Down Expand Up @@ -183,11 +185,11 @@ cleanMock();
## Development
* globally install `typescript` >= 1.8 (`npm install typescript -g`)
* globally install `typings` >= 1.0 (`npm install typings -g`)
* clone this repo
* `npm install`
* clone https://github.bus.zalan.do/graviton/graviton-typings in the parent directory of this repo
* `typings install`
* run `tsc` to compile
Expand Down
4 changes: 1 addition & 3 deletions integration-test/mock-tooling/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';

Expand All @@ -23,7 +21,7 @@ const ACCESS_TOKEN_ROUTE = '/access_token';
const tokeninfoEndpoint = HOST + TOKENINFO_ROUTE;
const accessTokenEndpoint = HOST + ACCESS_TOKEN_ROUTE;

describe('Integration tests for mock tooling', () => {
describe('mock tooling', () => {

describe('tokeninfo endpoint', () => {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as Express from 'express';
Expand All @@ -17,8 +15,8 @@ import {
chai.use(chaiAsPromised);
const expect = chai.expect;

// Setup API server
function setupTestEnvironment(authHeader: string, authServerApp: Express.Application) {

authServerApp.use(bodyParser.urlencoded({extended: true}));
authServerApp.post('/oauth2/access_token', function(req, res) {
if (req.body.grant_type === PASSWORD_CREDENTIALS_GRANT) {
Expand Down Expand Up @@ -53,7 +51,7 @@ function setupTestEnvironment(authHeader: string, authServerApp: Express.Applica
});
}

describe('Integration tests for getAccessToken', () => {
describe('getAccessToken', () => {

let authenticationServer: Http.Server;
let authServerApp: Express.Application;
Expand All @@ -71,9 +69,7 @@ describe('Integration tests for getAccessToken', () => {
authenticationServer.close();
});

// set up getAccessToken options object

describe('password oAuth flow', () => {
describe('password credentails grant', () => {

before(() => {
getAccessTokenOptions = {
Expand All @@ -92,6 +88,7 @@ describe('Integration tests for getAccessToken', () => {

//when
let promise = getAccessToken(getAccessTokenOptions);

//then
return expect(promise).to.become({access_token: '4b70510f-be1d-4f0f-b4cb-edbca2c79d41'});
});
Expand All @@ -108,7 +105,7 @@ describe('Integration tests for getAccessToken', () => {
return expect(promise).to.be.rejected;
});

it('should be jrected if credentials can not be read', function() {
it('should be rejected if credentials can not be read', function() {

//given
setupTestEnvironment('invalid', authServerApp);
Expand All @@ -124,7 +121,7 @@ describe('Integration tests for getAccessToken', () => {

});

describe('authorization_code oAuth flow', () => {
describe('authorization code grant', () => {
let getAccessTokenOptionsAuthorization;
before(() => {
getAccessTokenOptionsAuthorization = {
Expand Down Expand Up @@ -178,7 +175,5 @@ describe('Integration tests for getAccessToken', () => {
//then
return expect(promise).to.be.rejected;
});

});

});
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as Express from 'express';
Expand All @@ -13,7 +11,7 @@ import {
chai.use(chaiAsPromised);
const expect = chai.expect;

describe('Integration tests for getTokenInfo', () => {
describe('getTokenInfo', () => {

let authenticationServer: Http.Server;
let authServerApp: Express.Application;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as HttpStatus from 'http-status';
Expand All @@ -16,7 +14,7 @@ import {
chai.use(chaiAsPromised);
const expect = chai.expect;

describe('Integration tests for express middlewares', () => {
describe('middlewares', () => {

let authenticationServer: Http.Server;
let resourceServer: Http.Server;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import * as chai from 'chai';
import * as chaiAsPromised from 'chai-as-promised';
import * as HttpStatus from 'http-status';
Expand All @@ -14,7 +12,7 @@ import {
chai.use(chaiAsPromised);
const expect = chai.expect;

describe('token service', () => {
describe('tokenCache', () => {

let oauthConfig = {};
const oauthHost = 'http://auth.zalando.com/oauth2';
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": "lib-oauth-tooling",
"version": "0.18.0",
"version": "0.18.1",
"description": "A simple typescript based oauth tooling library.",
"main": "./lib/src/index.js",
"typings": "./lib/src/index.d.ts",
Expand Down
2 changes: 0 additions & 2 deletions src/TokenCache.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import {
getAccessToken,
getTokenInfo
Expand Down
2 changes: 0 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

export const AUTHORIZATION_CODE_GRANT = 'authorization_code';
export const PASSWORD_CREDENTIALS_GRANT = 'password';
export const SERVICES_REALM = '/services';
Expand Down
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import {
handleOAuthRequestMiddleware,
requireScopesMiddleware,
Expand Down
2 changes: 0 additions & 2 deletions src/mock-tooling/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import * as HttpStatus from 'http-status';
import * as nock from 'nock';
import * as uuid from 'node-uuid';
Expand Down
12 changes: 8 additions & 4 deletions src/oauth-tooling.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import * as HttpStatus from 'http-status';
import * as fetch from 'node-fetch';
import * as formurlencoded from 'form-urlencoded';
Expand Down Expand Up @@ -176,8 +174,7 @@ function getAccessToken(options: any): Promise<string> {
bodyParameters = {
'grant_type': options.grantType,
'username': userData.application_username,
'password': userData.application_password,
'scope': options.scopes.join(' ')
'password': userData.application_password
};
} else if (options.grantType === AUTHORIZATION_CODE_GRANT) {
bodyParameters = {
Expand All @@ -189,6 +186,13 @@ function getAccessToken(options: any): Promise<string> {
throw TypeError('invalid grantType');
}

// attach scope property if defined
if (options.scopes) {
Object.assign(bodyParameters, {
scope: options.scopes
});
}

const authorizationHeaderValue = getBasicAuthHeaderValue(clientData.client_id, clientData.client_secret);

return requestAccessToken(bodyParameters, authorizationHeaderValue,
Expand Down
2 changes: 0 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

import * as fs from 'fs';
import * as q from 'q';
import * as express from 'express';
Expand Down

0 comments on commit 97f0e4f

Please sign in to comment.