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

feat: new UserSession tied to a non-federated ArcGIS Server instance #423

Merged
merged 1 commit into from
Feb 12, 2019

Conversation

jgravois
Copy link
Contributor

@jgravois jgravois commented Dec 20, 2018

the proposed tweak to UserSession would enable developers to build up a UI of their own for users to enter credentials and access secure content from unfederated instances of ArcGIS Server.

import { request } from "@esri/arcgis-rest-request";
import { UserSession } from "@esri/arcgis-rest-auth";

const authentication = new UserSession({
  username: "user1",
  password: "user1",
  server: "https://sampleserver6.arcgisonline.com/arcgis"
});

request('https://sampleserver6.arcgisonline.com/arcgis/rest/services/Wildfire_secure/MapServer', { authentication })
  .then(token)

AFFECTS PACKAGES:
@esri/arcgis-rest-auth

ISSUES CLOSED: #174

@coveralls
Copy link

coveralls commented Dec 20, 2018

Coverage Status

Coverage decreased (-0.1%) to 99.862% when pulling 56d5a24 on f/non-federated into c1c9dd6 on master.

Copy link
Member

@tomwayson tomwayson left a comment

Choose a reason for hiding this comment

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

Thanks for taking this on @jgravois!

The API you propose makes sense to me, as does the idea of piggy-backing on trusted servers.

My main suggestions is to add more comments to 'splain this so we don't forget later what this is all about.

this.trustedServers = {};
if (options.server) {
this.trustedServers[options.server] = null;
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 I know why you're doing this, but probably a good idea to leave a comment here.

@@ -760,7 +790,8 @@ export class UserSession implements IAuthenticationManager {
params: {
username: this.username,
password: this.password,
expiration: this.tokenDuration
expiration: this.tokenDuration,
client: "referer"
Copy link
Member

Choose a reason for hiding this comment

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

Do we always want to send client=referer? Do we need to add that to above call to generateToken() too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it was only necessary in the case that i tweaked, but there's no harm in being consistent.

);
} else {
return request(
`${response.owningSystemUrl}/sharing/rest/info`,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a comment here to 'splain what this case is?

* if its a stand-alone instance of ArcGIS Server that doesn't advertise
* federation at all and the root url is recognized, use its built in token endpoint.
*/
return new Promise((resolve, reject) => {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just return Promise.resolve({ authInfo: response.authInfo });

Copy link
Contributor Author

Choose a reason for hiding this comment

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

💡
👶

@tomwayson
Copy link
Member

@jgravois

I believe we'd also need to make further changes if we wanted to support @dbouwman's idea

where the consuming app has the token (from a cookie, localstorage, some other auth flow managed by the app), but not the username/password?

Maybe set the token here?

#423 (diff)

@jgravois
Copy link
Contributor Author

jgravois commented Dec 21, 2018

where the consuming app has the token (from a cookie, localstorage, some other auth flow managed by the app), but not the username/password?

i've added another small tweak to support the use case you mentioned. this is what needs to be provided to invoke it:

const authentication = new UserSession({
  server: "https://sampleserver6.arcgisonline.com/arcgis",
  token: "SOSlV3v1wOOSN75azMS..",
  tokenExpires: new Date(1545415669763)
});

to do:

  • get @patrickarlt's blessing
  • refactor the trusted server check to compare only root urls
  • add a few more tests.

(i'll wait on the first to do the second and third)

@jgravois jgravois changed the title feat: add support for creating a UserSession tied to a non-federated ArcGIS Server instance feat: new UserSession tied to a non-federated ArcGIS Server instance Dec 21, 2018
@jgravois
Copy link
Contributor Author

jgravois commented Jan 7, 2019

@patrickarlt given that you chimed in on #422 but not this PR i'll assume you aren't fundamentally opposed to providing a mechanism to support making requests to non-federated, authenticated services.

i know you're busy with https://developers.arcgis.com tasks so if i'm wrong even a quick "hold your horses, i haven't had time to look at this yet and i'd like to", sometime this week would be welcome.

@patrickarlt
Copy link
Contributor

@jgravois I realized that you asked about this again ago but it all looks good to me. I figured at some point someone would ask for this, I just didn't want to do it.

@jgravois
Copy link
Contributor Author

thanks @patrickarlt!

i've rebased and pushed up some more changes to ensure test coverage and tie up the remaining loose ends. i'm happy with this if @tomwayson is.

… services

AFFECTS PACKAGES:
@esri/arcgis-rest-auth

ISSUES CLOSED: #174
@codecov
Copy link

codecov bot commented Feb 12, 2019

Codecov Report

Merging #423 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #423   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          94     94           
  Lines        1192   1202   +10     
  Branches      210    216    +6     
=====================================
+ Hits         1192   1202   +10
Impacted Files Coverage Δ
packages/arcgis-rest-auth/src/UserSession.ts 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bbdac40...fc2f06b. Read the comment docs.

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