Skip to content

Commit

Permalink
refactor(types): review comments
Browse files Browse the repository at this point in the history
close #41
  • Loading branch information
Retro64 committed Apr 19, 2017
1 parent 9daa995 commit eb6d250
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 47 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import {
} from 'lib-oauth-tooling';
```

#### TokenCache(tokenConfig: { [key : string]: string[] }, oauthConfig: OAuthConfig)
#### TokenCache(tokenConfig: { [key: string]: string[] }, oauthConfig: OAuthConfig)

Class to request and cache tokens on client-side.

Expand Down
14 changes: 7 additions & 7 deletions integration-test/mock-tooling/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ describe('mock tooling', () => {
expect(token).to.equal(validAuthToken);
return getTokenInfo(tokeninfoEndpoint, 'foo');
})
.then((token : TokenInfo) => {
.then((token: TokenInfo) => {

expect(token).to.equal(validAuthToken);
return getTokenInfo(tokeninfoEndpoint, 'foo');
})
.then((token : TokenInfo) => {
.then((token: TokenInfo) => {

expect(token).to.equal(validAuthToken);
return getTokenInfo(tokeninfoEndpoint, 'foo');
Expand All @@ -119,22 +119,22 @@ describe('mock tooling', () => {

// when
return getTokenInfo(tokeninfoEndpoint, 'foo')
.then((token : TokenInfo) => {
.then((token: TokenInfo) => {

expect(token).to.deep.equal(validAuthToken);
return getTokenInfo(tokeninfoEndpoint, 'foo');
})
.then((token : TokenInfo) => {
.then((token: TokenInfo) => {

expect(token).to.deep.equal(validAuthToken);
return getTokenInfo(tokeninfoEndpoint, 'foo');
})
.then((token : TokenInfo) => {
.then((token: TokenInfo) => {

expect(token).to.deep.equal(validAuthToken);
return getTokenInfo(tokeninfoEndpoint, 'foo');
})
.then((token : TokenInfo) => {
.then((token: TokenInfo) => {

expect(token).to.deep.equal(validAuthToken);
});
Expand Down Expand Up @@ -167,7 +167,7 @@ describe('mock tooling', () => {

// when
const promise = getAccessToken(options)
.then((token : Token) => {
.then((token: Token) => {

return getTokenInfo(tokeninfoEndpoint, token.access_token);
});
Expand Down
4 changes: 2 additions & 2 deletions integration-test/oauth-tooling/getAccessToken.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function setupTestEnvironment(authHeader: string, authServerApp: Express.Applica
.status(HttpStatus.UNAUTHORIZED)
.send({
error: 'internal_error',
error_description : 'Request method GET not supported'
error_description: 'Request method GET not supported'
});
}
}
Expand All @@ -59,7 +59,7 @@ describe('getAccessToken', () => {
let authenticationServer: Http.Server;
let authServerApp: Express.Application;

let getAccessTokenOptions : OAuthConfig;
let getAccessTokenOptions: OAuthConfig;

// Setup AuthServer
beforeEach(() => {
Expand Down
4 changes: 2 additions & 2 deletions integration-test/oauth-tooling/tokenCache.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const expect = chai.expect;

describe('tokenCache', () => {

let oauthConfig : OAuthConfig;
let oauthConfig: OAuthConfig;
const oauthHost = 'http://auth.zalando.com/oauth2';

before(() => {
Expand Down Expand Up @@ -324,7 +324,7 @@ describe('tokenCache', () => {
'uid': 'uid',
'access_token': firstAccessToken
})
.post('/access_token?realm=/services', function (body : any) {
.post('/access_token?realm=/services', function (body: any) {
return body.scope === 'all';
})
.reply(HttpStatus.OK, {
Expand Down
46 changes: 23 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,32 @@
"node": ">=6.0"
},
"dependencies": {
"body-parser": "^1.17.1",
"btoa": "^1.1.2",
"form-urlencoded": "^1.5.0",
"http-status": "^1.0.1",
"nock": "^9.0.13",
"node-fetch": "^1.6.3",
"uuid": "^3.0.1",
"q": "^1.5.0"
"body-parser": "1.17.1",
"btoa": "1.1.2",
"form-urlencoded": "1.5.0",
"http-status": "1.0.1",
"nock": "9.0.13",
"node-fetch": "1.6.3",
"uuid": "3.0.1",
"q": "1.5.0"
},
"devDependencies": {
"@types/body-parser": "^1.16.3",
"@types/chai": "^3.5.0",
"@types/body-parser": "1.16.3",
"@types/chai": "3.5.1",
"@types/chai-as-promised": "0.0.30",
"@types/express": "^4.0.35",
"@types/http-status": "^0.2.29",
"@types/mocha": "^2.2.40",
"@types/nock": "^8.2.1",
"@types/node-fetch": "^1.6.7",
"@types/q": "^1.0.0",
"@types/uuid": "^2.0.29",
"chai": "^3.5.0",
"chai-as-promised": "^6.0.0",
"express": "^4.15.2",
"mocha": "^3.2.0",
"tslint": "~4.4.2",
"typescript": "^2.3.0"
"@types/express": "4.0.35",
"@types/http-status": "0.2.29",
"@types/mocha": "2.2.40",
"@types/nock": "8.2.1",
"@types/node-fetch": "1.6.7",
"@types/q": "1.0.0",
"@types/uuid": "2.0.29",
"chai": "3.5.0",
"chai-as-promised": "6.0.0",
"express": "4.15.2",
"mocha": "3.2.0",
"tslint": "4.4.2",
"typescript": "2.3.0"
},
"scripts": {
"test": "tsc && mocha lib/test lib/integration-test --recursive",
Expand Down
18 changes: 9 additions & 9 deletions src/TokenCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TokenCache {
* @param tokenConfig
* @param oauthConfig
*/
constructor(private tokenConfig : { [key : string]: string[] }, private oauthConfig : OAuthConfig) {
constructor(private tokenConfig: { [key: string]: string[] }, private oauthConfig: OAuthConfig) {

validateOAuthConfig(oauthConfig);

Expand All @@ -52,8 +52,8 @@ class TokenCache {
* @param {string} The key configured on the tokenCache instance
* @return {Promise<string>} the resolved access_token
*/
public resolveAccessTokenFactory(key : string) : () => Promise < string > {
return() => this
public resolveAccessTokenFactory(key: string): () => Promise<string> {
return () => this
.get(key)
.then(tokenInfo => tokenInfo.access_token);
}
Expand All @@ -65,7 +65,7 @@ class TokenCache {
* @param tokenName
* @returns {Promise<T>}
*/
get(tokenName : string) : Promise <TokenInfo> {
get(tokenName: string): Promise<TokenInfo> {

const promise = new Promise((resolve, reject) => {

Expand All @@ -83,7 +83,7 @@ class TokenCache {
.then((token: Token) => {

return getTokenInfo(this.oauthConfig.tokenInfoEndpoint, token.access_token);
}).then((tokenInfo : TokenInfo) => {
}).then((tokenInfo: TokenInfo) => {

tokenInfo.local_expiry = Date.now() + tokenInfo.expires_in * 1000 - EXPIRE_THRESHOLD;
this._tokens[tokenName] = tokenInfo;
Expand All @@ -106,7 +106,7 @@ class TokenCache {
* @param tokenName
* @returns {Promise<TokenInfo>}
*/
refreshToken(tokenName : string) : Promise <TokenInfo> {
refreshToken(tokenName: string): Promise<TokenInfo> {

this._tokens[tokenName] = undefined;

Expand All @@ -120,7 +120,7 @@ class TokenCache {
*
* @returns {Promise<T>}
*/
refreshAllTokens() : Promise <{ [key : string]: TokenInfo }> {
refreshAllTokens(): Promise<{ [key: string]: TokenInfo }> {

const refreshPromises = Object
.keys(this.tokenConfig)
Expand All @@ -141,7 +141,7 @@ class TokenCache {
* @param tokenName
* @returns {Promise<T>}
*/
private validateToken(tokenName : string) : Promise <TokenInfo> {
private validateToken(tokenName: string): Promise<TokenInfo> {

if (!this.tokenConfig[tokenName]) {
throw Error(`Token ${tokenName} does not exist.`);
Expand All @@ -166,4 +166,4 @@ class TokenCache {
}
}

export {TokenCache};
export { TokenCache };
2 changes: 1 addition & 1 deletion src/express-tooling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function handleOAuthRequestMiddleware(options: MiddlewareOptions) {
return function(req: any, res: any, next: Function) {

// Skip OAuth validation for paths marked as public
if (options.publicEndpoints && match(req.originalUrl, new Set(options.publicEndpoints))) {
if (options.publicEndpoints && match(req.originalUrl, new Set(options.publicEndpoints))) {
return next();
}

Expand Down
2 changes: 1 addition & 1 deletion src/mock-tooling/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as nock from 'nock';
import * as uuid from 'uuid';
import * as url from 'url';

let tokens : TokenInfo[] = [];
let tokens: TokenInfo[] = [];

function generateToken(): TokenInfo {

Expand Down
2 changes: 1 addition & 1 deletion src/oauth-tooling.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function getAccessToken(options: OAuthConfig): Promise<Token> {
const userData = JSON.parse(credentials[0]);
const clientData = JSON.parse(credentials[1]);

let bodyParameters: any;
let bodyParameters: BodyParameters;

if (options.grantType === PASSWORD_CREDENTIALS_GRANT) {
bodyParameters = {
Expand Down
8 changes: 8 additions & 0 deletions src/types/BodyParameters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
interface BodyParameters {
grant_type: string;
username?: string;
password?: string;
code?: string;
redirect_uri?: string;
refresh_token?: string;
}

0 comments on commit eb6d250

Please sign in to comment.