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

Don't try to set cookie from hash during OAuth login #190

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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