Skip to content

Feature: Add X-Stormpath-Agent header#31

Merged
timothyej merged 5 commits intomasterfrom
feature-add-stormpath-agent-header
Feb 24, 2016
Merged

Feature: Add X-Stormpath-Agent header#31
timothyej merged 5 commits intomasterfrom
feature-add-stormpath-agent-header

Conversation

@typerandom
Copy link
Copy Markdown
Contributor

Adds the X-Stormpath-Agent header to all API requests.

How to verify
  1. Checkout this branch.
  2. Link it ($ npm link).
  3. Clone the React example app.
  4. Link to the feature branch ($ npm link react-stormpath).
  5. Start the app ($ npm start).
  6. Navigate to the login page.
  7. Open up the network console and try to login.
  8. Assert that the POST request to /login contains the header X-Stormpath-Agent: react-stormpath/0.5.0.

Fixes #30.

Comment thread src/services/UserService.js Outdated

request.open(method.toUpperCase(), path, true);
request.setRequestHeader('Accept', 'application/json');
request.setRequestHeader('X-Stormpath-Agent', pkg.name + '/' + pkg.version);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please see my comment on @robertjd's PR regarding if we should include the framework version as well (in this case react/x.x.x).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, that might be interesting. I'm going to add that too.

@timothyej
Copy link
Copy Markdown
Contributor

I've verified that this works as expected in Chrome, Safari, and Firefox 👍

But please see my comment regarding also including the React version. And also, Robert excluded this header for CORS requests from the Angular SDK. Will you save that for when you add CORS support?

@typerandom
Copy link
Copy Markdown
Contributor Author

@timothyej Thanks!

I don't think it's necessary to exclude the header for CORS requests since it only requires the users to add add support for that header.

@timothyej
Copy link
Copy Markdown
Contributor

Yes, but then it also requires them to do that in order to get it to work, which adds more friction since it doesn't provide any value for the user. I guess that was @robertjd's thoughts as well?

@robertjd
Copy link
Copy Markdown
Member

@typerandom please remove the header if the request is cross-domain. Otherwise, the user will have to add our custom header to their server-side configuration. We don't want to burden the developer with this. See DOM API usage here. Thanks!

@typerandom
Copy link
Copy Markdown
Contributor Author

@robertjd Sure, will fix that.

@typerandom
Copy link
Copy Markdown
Contributor Author

@robertjd This is now fixed. I refactored a few things at the same time. The important line to review is this one: https://github.com/stormpath/stormpath-sdk-react/pull/31/files#diff-12ab8b19aebc183c7b26d5fe0f102c6bR60

Comment thread src/services/BaseService.js Outdated

// Only set the X-Stormpath-Agent header if we're on the same domain as the requested URI.
// This because we want to avoid CORS requests that require you to have to whitelist the X-Stormpath-Agent header.
if (!utils.isSameHost(uri, window.location.href)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think you should remove the !, right? Otherwise this will add the header if they're not on the same host.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's correct. I've fixed that.

@typerandom typerandom force-pushed the feature-add-stormpath-agent-header branch from e00920f to 0605c61 Compare February 24, 2016 13:08
@typerandom
Copy link
Copy Markdown
Contributor Author

@timothyej Please review again :)

@timothyej
Copy link
Copy Markdown
Contributor

I've verified that this works as expected in Chrome, Safari, and Firefox 👍

timothyej pushed a commit that referenced this pull request Feb 24, 2016
@timothyej timothyej merged commit 2a0f990 into master Feb 24, 2016
@timothyej timothyej deleted the feature-add-stormpath-agent-header branch February 24, 2016 13:37
@typerandom
Copy link
Copy Markdown
Contributor Author

\o/ thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants