diff options
author | anonymous | 2022-09-21 12:46:08 -0400 |
---|---|---|
committer | anonymous | 2022-09-21 12:46:08 -0400 |
commit | 7c33c03c2613651b775218b363f38c3493006789 (patch) | |
tree | 90366fa0908bae46c10d2e57602e42b92d9dddff | |
parent | dd352a3a167b272ab0c2c81c9942b8a9a636944d (diff) |
differences to url naming
-rw-r--r-- | src/auth.js | 27 | ||||
-rw-r--r-- | src/socket.js | 10 |
2 files changed, 21 insertions, 16 deletions
diff --git a/src/auth.js b/src/auth.js index 697c61e..76cb554 100644 --- a/src/auth.js +++ b/src/auth.js @@ -2,7 +2,7 @@ import { randomString, sha256 } from './utils.js' export default { - async logIn(origin) { + async logIn(graffitiURL) { // Generate a random client secret and state const clientSecret = randomString() const state = randomString() @@ -16,16 +16,14 @@ export default { window.localStorage.setItem('graffitiAuthState', state) // Redirect to the login window - const authURL = new URL(origin) - authURL.searchParams.set('client_id', clientID) - authURL.searchParams.set('redirect_uri', window.location.href) - authURL.searchParams.set('state', state) - window.location.href = authURL + const loginURL = this.authURL(graffitiURL) + loginURL.searchParams.set('client_id', clientID) + loginURL.searchParams.set('redirect_uri', window.location.href) + loginURL.searchParams.set('state', state) + window.location.href = loginURL }, - async connect(origin) { - origin = new URL(origin) - origin.host = "auth." + origin.host + async connect(graffitiURL) { // Check to see if we are already logged in let token = window.localStorage.getItem('graffitiToken') @@ -64,7 +62,8 @@ export default { form.append('code', code) // Ask to exchange the code for a token - const tokenURL = new URL('token', origin) + const tokenURL = this.authURL(graffitiURL) + tokenURL.pathname = '/token' const response = await fetch(tokenURL, { method: 'post', body: form @@ -98,7 +97,7 @@ export default { } } - const loggedIn = (token != null) && (myID != null), + const loggedIn = (token != null) && (myID != null) return { loggedIn, myID, token } @@ -110,4 +109,10 @@ export default { window.location.reload() }, + authURL(graffitiURL) { + const url = new URL(graffitiURL) + url.host = "auth." + url.host + return url + }, + } diff --git a/src/socket.js b/src/socket.js index d324b78..1f762db 100644 --- a/src/socket.js +++ b/src/socket.js @@ -3,8 +3,8 @@ import { randomString } from './utils.js' export default class { - constructor(origin="https://graffiti.csail.mit.edu") { - this.origin = origin + constructor(graffitiURL="https://graffiti.csail.mit.edu") { + this.graffitiURL = graffitiURL this.open = false this.subscriptionData = {} this.eventTarget = new EventTarget() @@ -13,10 +13,10 @@ export default class { // CALL THIS BEFORE DOING ANYTHING ELSE async initialize() { // Perform authorization - this.authParams = await Auth.connect(this.origin) + this.authParams = await Auth.connect(this.graffitiURL) // Rewrite the URL - this.wsURL = new URL(origin) + this.wsURL = new URL(this.graffitiURL) this.wsURL.host = "app." + this.wsURL.host if (this.wsURL.protocol == 'https:') { this.wsURL.protocol = 'wss:' @@ -39,7 +39,7 @@ export default class { } // authorization functions - logIn() { Auth.logIn(this.origin) } + logIn() { Auth.logIn(this.graffitiURL) } logOut() { Auth.logOut() } get myID() { return this.authParams.myID } get loggedIn() { return this.authParams.loggedIn } |