Skip to content

Commit

Permalink
Don't try to set cookie from hash during OAuth login
Browse files Browse the repository at this point in the history
Fixes #188
  • Loading branch information
zachmullen committed Oct 11, 2019
1 parent 6ab9945 commit 1230e96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
8 changes: 6 additions & 2 deletions src/components/Authentication/Authentication.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ v-card.girder-authentication-component
<script>
import GirderLogin from './Login.vue';
import GirderRegistration from './Register.vue';
import { OauthTokenPrefix, OauthTokenSuffix } from '../../rest';
export default {
inject: ['girderRest'],
Expand All @@ -35,6 +34,11 @@ export default {
type: Boolean,
default: false,
},
/* Redirect URL for end of OAuth login flow. If not passed uses current URL. */
oauthRedirect: {
type: String,
default: null,
},
/* A full URL to be used as an anchor href to an external page. */
forgotPasswordUrl: {
type: String,
Expand Down Expand Up @@ -66,7 +70,7 @@ export default {
try {
return (await this.girderRest.get('oauth/provider', {
params: {
redirect: `${window.location.href}${OauthTokenPrefix}{girderToken}${OauthTokenSuffix}`,
redirect: this.oauthRedirect || window.location.href,
list: true,
},
})).data;
Expand Down
22 changes: 1 addition & 21 deletions src/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@ import cookies from 'js-cookie';
import { stringify } from 'qs';
import Vue from 'vue';

const GirderTokenLength = 64;
export const OauthTokenPrefix = '#girderToken=';
export const OauthTokenSuffix = '__';

// Girder's custom headers
const GirderToken = 'Girder-Token';
const GirderOtp = 'Girder-OTP';
Expand All @@ -16,22 +12,6 @@ function setCookieFromAuth(auth) {
cookies.set('girderToken', auth.token, { expires: new Date(auth.expires) });
}

/**
* set cookie if special string is found in the hash.
* @param {Location} location
*/
function setCookieFromHash(location) {
const arr = location.hash.split(OauthTokenPrefix);
const token = arr[arr.length - 1].split(OauthTokenSuffix)[0];
if (token.length === GirderTokenLength) {
const expires = new Date();
expires.setDate((new Date()).getDate() + 365);
setCookieFromAuth({ token, expires });
location.hash = location.hash.replace(`${OauthTokenPrefix}${token}${OauthTokenSuffix}`, '');
}
return token;
}

/**
* This is a subclass of axios that is meant to add Girder-specific helper functionality.
*/
Expand All @@ -49,7 +29,7 @@ export default class RestClient extends Vue {
*/
constructor({
apiRoot = '/api/v1',
token = cookies.get('girderToken') || setCookieFromHash(window.location),
token = cookies.get('girderToken'),
axios = axios_.create(),
useGirderAuthorizationHeader = false,
setLocalCookie = true,
Expand Down

0 comments on commit 1230e96

Please sign in to comment.