Skip to content

Commit

Permalink
Merge pull request #32 from ImageMarkup/isi-74-remove-legacy-token-su…
Browse files Browse the repository at this point in the history
…pport
  • Loading branch information
brianhelba authored Apr 10, 2023
2 parents 256fc00 + 92f5796 commit a5ceeaa
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 48 deletions.
23 changes: 2 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,45 +44,27 @@ A client library for authenticating with the ISIC Archive from an SPA (single pa

* At the start of *every* page load, unconditionally call `maybeRestoreLogin`, to attempt to
restore a login state; this will no-op if no login is present. Afterwards, get and store HTTP
headers for new API accesses from `authHeaders`. Finally, if the client is logged in, get and store
a token for legacy API accesses from `getLegacyToken`.
headers for new API accesses from `authHeaders`.
```js
let authHeaders;
let legacyToken;
isicClient.maybeRestoreLogin()
.then(() => {
authHeaders = isicClient.authHeaders;
})
.then(() => {
if (isicClient.isLoggedIn) {
return isicClient.getLegacyToken();
} else {
return null;
}
})
.then((_legacyToken) => {
legacyToken = _legacyToken;
})
```

or, if using ES6 and `async`/`await`:
```js
await isicClient.maybeRestoreLogin();
let { authHeaders } = isicClient;
let legacyToken = isicClient.isLoggedIn ? await isicClient.getLegacyToken() : null;
```
* Use these credentials for Ajax API requests:
```js
fetch('https://api.isic-archive.com/api/v2/studies/', {
headers: authHeaders,
});
fetch('https://isic-archive.com/api/v1/studies/', {
headers: {
'Girder-Token': legacyToken,
},
});
```
* The login state will persist across page refreshes. Call `logout` to clear any active login:
Expand All @@ -92,7 +74,6 @@ A client library for authenticating with the ISIC Archive from an SPA (single pa
isicClient.logout()
.then(() => {
authHeaders = isicClient.authHeaders;
legacyToken = null;
});
});
```
4 changes: 0 additions & 4 deletions example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@
Auth Headers:
<span id="auth-headers"></span>
</p>
<p>
Legacy Token:
<span id="legacy-token"></span>
</p>
<script src="./index.js" type="module"></script>
</body>
</html>
15 changes: 0 additions & 15 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const isicClient = new IsicClient(
scopes: ['identity'],
},
);
let legacyToken;

function updateDom() {
document.querySelector('#sign-in-link').style.visibility =
Expand All @@ -17,7 +16,6 @@ function updateDom() {

document.querySelector('#logged-in').innerHTML = JSON.stringify(isicClient.isLoggedIn);
document.querySelector('#auth-headers').innerHTML = JSON.stringify(isicClient.authHeaders);
document.querySelector('#legacy-token').innerHTML = JSON.stringify(legacyToken);
}

document.querySelector('#sign-in-link')
Expand All @@ -29,23 +27,10 @@ document.querySelector('#sign-out-link')
.addEventListener('click', (event) => {
event.preventDefault();
isicClient.logout()
.then(() => {
legacyToken = null;
})
.then(updateDom);
});

updateDom();

isicClient.maybeRestoreLogin()
.then(() => {
if (isicClient.isLoggedIn) {
return isicClient.getLegacyToken();
} else {
return null;
}
})
.then((_legacyToken) => {
legacyToken = _legacyToken;
})
.then(updateDom);
8 changes: 0 additions & 8 deletions src/isic-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,4 @@ export default class IsicClient extends OauthClient {
}
return resp.json();
}

public async getLegacyToken(): Promise<string> {
interface LegacyTokenResponse {
token: string;
}
const resp = await this.fetchJson<LegacyTokenResponse>('api/v2/token/legacy', 'POST');
return resp.token;
}
}

0 comments on commit a5ceeaa

Please sign in to comment.