|
62 | 62 | diam. |
63 | 63 | </p> |
64 | 64 | </div> |
65 | | -<script type="module" src="../dist/index.js"></script> |
66 | | -<script> |
67 | | -</script> |
68 | | -<script type="module"> |
| 65 | +<script src="https://unpkg.com/@frontify/frontify-authenticator@latest/dist/index.js"></script> |
| 66 | +<script"> |
69 | 67 | import {authorize, revoke, refresh} from "../dist/index.es.js"; |
70 | 68 | const POPUP_CONFIG = { |
71 | 69 | width: 800, |
|
80 | 78 | scopes: ["basic:read", "finder:read", "account:read"], |
81 | 79 | }; |
82 | 80 |
|
83 | | - let domain = ''; |
84 | | - let token = null; |
85 | | - |
| 81 | + let token = localStorage.getItem('FrontifyAuthenticatorToken'); |
| 82 | + |
86 | 83 | function authorizeAction() { |
87 | | - // handle domain window |
88 | 84 | if (!token) { |
89 | | - authorize(AUTHORIZATION_CONFIG, POPUP_CONFIG).then(res => { |
90 | | - if (res) { |
91 | | - domain = res.domain; |
92 | | - token = res; |
93 | | - } |
94 | | - }).catch((err) => { |
95 | | - console.log(err); |
96 | | - }); |
97 | | - } else { |
98 | | - console.log(token); |
| 85 | + FrontifyAuthenticator.authorize(AUTHORIZATION_CONFIG, POPUP_CONFIG) |
| 86 | + .then((res) => { |
| 87 | + if (res) { |
| 88 | + localStorage.setItem('FrontifyAuthenticatorToken', JSON.stringify(res)); |
| 89 | + token = localStorage.getItem('FrontifyAuthenticatorToken'); |
| 90 | + } |
| 91 | + }) |
| 92 | + .catch((err) => { |
| 93 | + console.log(err); |
| 94 | + }); |
99 | 95 | } |
100 | 96 | } |
101 | 97 |
|
102 | | - |
103 | 98 | function revokeAction() { |
104 | 99 | if (!token) { |
| 100 | + console.log('Nothing to revoke! No token available'); |
105 | 101 | return; |
106 | 102 | } |
107 | 103 |
|
108 | | - revoke(token).then(res => { |
109 | | - token = null; |
110 | | - delete(AUTHORIZATION_CONFIG.domain); |
111 | | - }); |
| 104 | + FrontifyAuthenticator.revoke(JSON.parse(token)) |
| 105 | + .then((res) => { |
| 106 | + if (res) { |
| 107 | + localStorage.removeItem('FrontifyAuthenticatorToken'); |
| 108 | + token = null; |
| 109 | + delete AUTHORIZATION_CONFIG.domain; |
| 110 | + } |
| 111 | + }) |
| 112 | + .catch((error) => { |
| 113 | + console.log(error); |
| 114 | + }); |
112 | 115 | } |
113 | 116 |
|
114 | 117 | function refreshAction() { |
115 | 118 | if (!token) { |
| 119 | + console.log('Nothing to refresh! No token available'); |
116 | 120 | return; |
117 | 121 | } |
118 | 122 |
|
119 | | - refresh(token).then(res => { |
120 | | - token = res; |
121 | | - }); |
| 123 | + FrontifyAuthenticator.refresh(JSON.parse(token)) |
| 124 | + .then((res) => { |
| 125 | + if (res) { |
| 126 | + localStorage.setItem('FrontifyAuthenticatorToken', JSON.stringify(res)); |
| 127 | + token = localStorage.getItem('FrontifyAuthenticatorToken'); |
| 128 | + } |
| 129 | + }) |
| 130 | + .catch((error) => { |
| 131 | + console.log(error); |
| 132 | + }); |
122 | 133 | } |
123 | 134 |
|
124 | 135 | document.getElementById('authorize').addEventListener('click', authorizeAction); |
|
0 commit comments