Skip to content

Commit

Permalink
Esri#295: fetchToken returns ssl property with response.
Browse files Browse the repository at this point in the history
  • Loading branch information
skitterm committed Sep 20, 2018
1 parent 65c0b82 commit 1dba15d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/arcgis-rest-auth/src/UserSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ export class UserSession implements IAuthenticationManager {
return new UserSession({
clientId,
portal,
ssl: response.ssl,
redirectUri,
refreshToken: response.refreshToken,
refreshTokenTTL,
Expand Down
7 changes: 4 additions & 3 deletions packages/arcgis-rest-auth/src/fetch-token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ interface IFetchTokenRawResponse {
access_token: string;
expires_in: number;
username: string;
ssl: boolean;
refresh_token?: string;
ssl?: boolean;
}

export interface IFetchTokenResponse {
token: string;
expires: Date;
username: string;
ssl: boolean;
refreshToken?: string;
ssl?: boolean;
}

export function fetchToken(
Expand All @@ -40,7 +40,8 @@ export function fetchToken(
username: response.username,
expires: new Date(
Date.now() + (response.expires_in * 60 * 1000 - 60 * 1000)
)
),
ssl: response.ssl === true
};
if (response.refresh_token) {
r.refreshToken = response.refresh_token;
Expand Down
8 changes: 7 additions & 1 deletion packages/arcgis-rest-auth/test/UserSession.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,8 @@ describe("UserSession", () => {
access_token: "token",
expires_in: 1800,
refresh_token: "refreshToken",
username: "Casey"
username: "Casey",
ssl: true
});

UserSession.exchangeAuthorizationCode(
Expand All @@ -872,6 +873,11 @@ describe("UserSession", () => {
"code"
)
.then(session => {
expect(session.token).toBe("token");
expect(session.tokenExpires.getTime()).toBeGreaterThan(Date.now());
expect(session.username).toBe("Casey");
expect(session.refreshToken).toBe("refreshToken");
expect(session.ssl).toBe(true);
done();
})
.catch(e => {
Expand Down
8 changes: 6 additions & 2 deletions packages/arcgis-rest-auth/test/fetchToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ describe("fetchToken()", () => {
it("should request a token with `client_credentials`, `client_id` and `client_secret`", done => {
fetchMock.postOnce(TOKEN_URL, {
access_token: "token",
expires_in: 1800
expires_in: 1800,
ssl: false
});

fetchToken(TOKEN_URL, {
Expand All @@ -33,6 +34,7 @@ describe("fetchToken()", () => {
expect(options.body).toContain("grant_type=client_credentials");
expect(response.token).toEqual("token");
expect(response.expires).toBeGreaterThan(Date.now());
expect(response.ssl).toEqual(false);
done();
})
.catch(e => {
Expand All @@ -45,7 +47,8 @@ describe("fetchToken()", () => {
access_token: "token",
expires_in: 1800,
refresh_token: "refreshToken",
username: "Casey"
username: "Casey",
ssl: true
});

fetchToken(TOKEN_URL, {
Expand Down Expand Up @@ -74,6 +77,7 @@ describe("fetchToken()", () => {
expect(response.refreshToken).toEqual("refreshToken");
expect(response.username).toEqual("Casey");
expect(response.expires).toBeGreaterThan(Date.now());
expect(response.ssl).toEqual(true);
done();
})
.catch(e => {
Expand Down

0 comments on commit 1dba15d

Please sign in to comment.