-
Notifications
You must be signed in to change notification settings - Fork 0
/
token_flow.html
72 lines (66 loc) · 2.14 KB
/
token_flow.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<script>
/**
* This page demonstrates how to get an OAuth2 access token in the browser using
* the token flow (implicit grant).
*
* If your API integration supports it, implicit grant should be used in the browser
* over the code flow as it does not require exposing your client secret.
*/
</script>
<head></head>
<script src="/dist/js/aspera-on-cloud-sdk.js"></script>
</head>
<body>
<div>
<div id="not-authenticated" style="display:block">
<p>Click the link below to authenticate.</p>
<a href="" id="authenticate">Authenticate</a>
</div>
<div id="authenticated" style="display:none">
<p>If successful, you should see your account details:</p>
<p id="self"></p>
</div>
</div>
<script>
/**
* Insert your API client integration settings here as specified
* in the Aspera On Cloud Admin app.
*
* id - client id of your API client
* org - the organization or subdomain that your API client belongs to
* scope - desired grant access for the access token
*/
const CLIENT = {
id: 'CLIENT_ID',
org: 'ORG',
scope: ['admin-user:all', 'user:all']
};
function getAccessToken() {
return new URLSearchParams(window.location.search).get('access_token')
}
function toggleAuthSections() {
document.getElementById('not-authenticated').style.display = 'none';
document.getElementById('authenticated').style.display = 'block';
}
const options = {
clientId: CLIENT.id,
org: CLIENT.org,
redirectUri: 'https://localhost:3000'
};
const aoc = new AsperaOnCloud(options);
const accessToken = getAccessToken();
if (!accessToken) {
const oauthUrl = aoc.auth.getOauthUrl(undefined, CLIENT.scope, 'token');
document.getElementById('authenticate').href = oauthUrl;
} else {
toggleAuthSections();
aoc.setAccessToken(accessToken);
aoc.getSelf()
.then(res => {
const selfContainer = document.getElementById('self');
selfContainer.innerText = JSON.stringify(res.data);
})
.catch(err => console.error(err));
}
</script>
</body>