Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ssl flag #332

Merged
merged 6 commits into from
Sep 20, 2018
Merged

Add ssl flag #332

merged 6 commits into from
Sep 20, 2018

Conversation

skitterm
Copy link

@skitterm skitterm commented Sep 20, 2018

Addresses #295.

Features

  • Adds ssl field to UserSession class and FetchToken response
  • Reads/writes to that field in to/fromCredential, deserialize and toJSON
  • Reads oauth-callback hash for ssl property in completeOAuth2
  • Reads oauth2/token response for ssl property in exchangeAuthorizationCode

Future work needed (not included in this PR)

  • Ideally arcgis-rest-request methods (and other requests when authenticated) should look for ssl property and force the URL to always be HTTPS in that case
  • Does ApplicationSession need this ssl property as well?
  • Does UserSession.getToken method need to read ssl value?

@coveralls
Copy link

coveralls commented Sep 20, 2018

Coverage Status

Coverage remained the same at 100.0% when pulling f80f4f8 on skitterm:add-ssl-flag into 30fadcb on Esri:master.

@@ -12,13 +12,15 @@ interface IFetchTokenRawResponse {
access_token: string;
expires_in: number;
username: string;
ssl: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this should be ssl?: boolean?

@tomwayson
Copy link
Member

Nice work @skitterm, thanks for the contribution!

@@ -165,6 +165,11 @@ export interface IUserSessionOptions {
*/
portal?: string;

/**
* Whether requests should be made exlusively over HTTPS.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exclusively 😈

@@ -456,10 +469,14 @@ export class UserSession implements IAuthenticationManager {
Date.now() + parseInt(match[2], 10) * 1000 - 60 * 1000
);
const username = decodeURIComponent(match[3]);
const ssl =
win.location.href.indexOf("&ssl=true") !== -1 ||
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this may just be me, but .indexOf("&ssl=true") > -1 feels more readable than a double-negative.

packages/arcgis-rest-auth/src/fetch-token.ts Show resolved Hide resolved
@@ -19,6 +19,7 @@ describe("UserSession", () => {
const session = new UserSession({
clientId: "clientId",
redirectUri: "https://example-app.com/redirect-uri",
ssl: false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless i'm missing something, there's nothing a user can do in the UserSession constructor to dicate what the server is going to respond with so there's no point in including ssl as an option.

is that correct? if so, we just need to update our examples and make that clear in the API reference.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking is that ssl is an attribute of a user session, and something that would be needed by arcgis-rest-request's request methods (since they take in a UserSession/ApplicationSession as a param) to determine whether or not to force HTTPS for a request.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the main risk w/ the approach in this PR is that a user can set ssl before beginOAuth() which may overwrite whatever they set.

One alternative would be that we don't let consuming apps set this and we have some kind of read-only property/fn like sslOrg that always returns what was in the redirect url parameter.

Given that we haven't thought through how request() is going to use this parameter yet, it may be safer to do the latter. That would be a much more useful signal to request(). For example, it could so it could only force SSL for requests that are made to that org.

I'm open to suggestions though.

Copy link
Contributor

@jgravois jgravois left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i pushed up one more commit to make it a little clearer in the API reference that the property set internally and remove the last instance where it was set manually in a UserSession constructor.

@jgravois
Copy link
Contributor

awesome contribution. thank you @skitterm!

@skitterm
Copy link
Author

Should we then remove the this.ssl = options.ssl from the constructor itself? Though if we do, I feel like we'd still want to be able to set ssl property via a setter.

@jgravois
Copy link
Contributor

jgravois commented Sep 20, 2018

Should we then remove the this.ssl = options.ssl from the constructor itself?

i didn't spend long with it, but the way things are set up now its necessary in order to be able to set the property internally later.

@jgravois jgravois merged commit e0d57d9 into Esri:master Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants