Skip to content

Commit

Permalink
Merge pull request #429 from Esri/patch/314
Browse files Browse the repository at this point in the history
fix: expose option to customize expiration of ApplicationSession tokens
  • Loading branch information
john gravois authored Jan 11, 2019
2 parents d085fad + 05ff607 commit 94b7bf5
Show file tree
Hide file tree
Showing 16 changed files with 267 additions and 261 deletions.
37 changes: 23 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"ts-node": "^3.3.0",
"tslint": "^5.11.0",
"tslint-config-prettier": "^1.6.0",
"tslint-config-standard": "^6.0.1",
"tslint-config-standard": "^8.0.1",
"typedoc": "^0.12.0",
"typescript": "^3.0.0"
},
Expand All @@ -75,7 +75,7 @@
},
"scripts": {
"build": "lerna run build",
"test": "npm run test:node && npm run test:chrome",
"test": "npm run lint && npm run test:node && npm run test:chrome",
"test:chrome:debug": "karma start --auto-watch --no-single-run --browsers=Chrome",
"test:chrome": "karma start --single-run --browsers=Chrome",
"test:chrome:ci": "karma start --single-run --browsers ChromeHeadlessCI karma.conf.js",
Expand Down
18 changes: 13 additions & 5 deletions packages/arcgis-rest-auth/src/ApplicationSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ export interface IApplicationSessionOptions {
* Expiration date for the `token`
*/
expires?: Date;

/**
* URL of ArcGIS REST base, defaults to "https://www.arcgis.com/sharing/rest"
*/
portal?: string;

/**
* Duration of requested tokens in minutes. defaults to 7200 (5 days).
*/
duration?: number;
}

/**
Expand All @@ -56,6 +61,7 @@ export class ApplicationSession implements IAuthenticationManager {
private clientSecret: string;
private token: string;
private expires: Date;
private duration: number;

/**
* Internal object to keep track of pending token requests. Used to prevent
Expand All @@ -69,10 +75,11 @@ export class ApplicationSession implements IAuthenticationManager {
this.token = options.token;
this.expires = options.expires;
this.portal = options.portal || "https://www.arcgis.com/sharing/rest";
this.duration = options.duration || 7200;
}

// url isnt actually read or passed through.
getToken(
public getToken(
url: string,
requestOptions?: ITokenRequestOptions
): Promise<string> {
Expand All @@ -89,12 +96,13 @@ export class ApplicationSession implements IAuthenticationManager {
return this._pendingTokenRequest;
}

refreshToken(requestOptions?: ITokenRequestOptions): Promise<string> {
public refreshToken(requestOptions?: ITokenRequestOptions): Promise<string> {
const options = {
params: {
client_id: this.clientId,
client_secret: this.clientSecret,
grant_type: "client_credentials"
grant_type: "client_credentials",
expiration: this.duration
},
...requestOptions
};
Expand All @@ -108,7 +116,7 @@ export class ApplicationSession implements IAuthenticationManager {
);
}

refreshSession() {
public refreshSession() {
return this.refreshToken().then(() => this);
}
}
Loading

0 comments on commit 94b7bf5

Please sign in to comment.