Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 22, 2019. It is now read-only.

fix: access token logic - #267

Merged
ijsnow merged 4 commits into
masterfrom
access-token-fix
Oct 25, 2018
Merged

fix: access token logic#267
ijsnow merged 4 commits into
masterfrom
access-token-fix

Conversation

@ijsnow

@ijsnow ijsnow commented Oct 25, 2018

Copy link
Copy Markdown

The problem: Chrome began rejecting requests from the browser extension options page saying that authorization headers weren't allowed from that origin (the chrome extension bundle ID). This PR fixes that by not using tokens on requests coming from the options page or background script. That change brought about another issue which was simply a result of an architecture decision in the PR that introduces access tokens. The problem is that tokens would never be created since they were done on an as-needed basis at the bottom of the funnel for each request. Right before any request went out, we'd check for a token and if it didn't exist we'd create one. Now, we create a token as soon as the user enters their sourcegraph URL and never again.

This commit fixes access token usage by:

  • Not setting the authorization header when
    requesting from the options page.
    Chrome suddenly began rejecting the request in
    pre-flight checks from the options page.

  • Only creating access tokens when the server connection is checked in the
    options page.

  • Save the access token ID so we can ensure it still exists on the
    server.

  • Chrome

  • Firefox

This commit fixes access token usage by:

- Not setting the `authorization` header when
requesting from the options page.
Chrome suddenly becan rejecting the request in
pre-flight checks from hte options page.
- _Only_ creating access tokens when the server connection is checked in the
options page.
- Save the access token ID so we can ensure it still exists on the
server.

@chrismwendt chrismwendt left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I mostly skimmed looking at style

Comment thread src/shared/components/options/ConnectionCard.tsx Outdated
Comment thread src/extension/scripts/background.tsx Outdated
for (const key of Object.keys(items.accessTokens)) {
const val = items.accessTokens[key]
if (typeof val !== 'string' && val.id && val.token) {
accessTokens[key] = val

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Nitpick: key/val are pretty vague - it took me a while to realize that key is the Sourcegraph URL and val is the token.

@ijsnow
ijsnow merged commit afe3ea3 into master Oct 25, 2018
@ijsnow
ijsnow deleted the access-token-fix branch October 25, 2018 01:02
@sourcegraph-bot

Copy link
Copy Markdown

🎉 This PR is included in version 1.18.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants