-
Notifications
You must be signed in to change notification settings - Fork 0
/
authorize.html
66 lines (58 loc) · 2.4 KB
/
authorize.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
<!DOCTYPE html>
<html>
<header>
<style>
</style>
<script src="https://p.trellocdn.com/power-up.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<script>
var Promise = TrelloPowerUp.Promise;
var t = TrelloPowerUp.iframe();
// When constructing the URL, remember that you'll need to encode your
// APPNAME and RETURNURL
// You can do that with the encodeURIComponent(string) function
// encodeURIComponent('Hello World') -> "Hello%20World"
var oauthUrl = 'https://trello.com/1/authorize?expiration=never' +
'&name=[APPNAME]&scope=read&key=[APIKEY]&callback_method=fragment' +
'&return_url=[RETURNURL]';
var storageHandler = function (evt) {
if (evt.key === 'token' && evt.newValue) {
// Do something with the token here, then...
authorizeWindow.close();
window.removeEventListener('storage', storageHandler);
}
}
var authorizeOpts = {
height: 680,
width: 580,
windowCallback: function (authorizeWindow) {
// This callback gets called with the handle to the
// authorization window. This can be useful if you
// can't call window.close() in your new window
// (such as the case when your authorization page
// is rendered inside an iframe).
window.addEventListener('storage', storageHandler);
}
};
var authBtn = document.getElementById('authorize');
authBtn.addEventListener('click', function () {
t.authorize(oauthUrl, authorizeOpts)
.then(function (token) {
return t.set('organization', 'private', 'token', token)
.catch(t.NotHandled, function () {
// fall back to storing at board level
return t.set('board', 'private', 'token', token);
});
})
.then(function () {
// now that the token is stored, we can close this popup
// you might alternatively choose to open a new popup
return t.closePopup();
});
});
</script>
</header>
<body>
test
</body>
</html>