|
62 | 62 | diam. |
63 | 63 | </p> |
64 | 64 | </div> |
65 | | -<div id="AuthenticatorFrame"></div> |
66 | 65 | <script type="module"> |
67 | 66 | import {authorize, revoke, refresh} from "../dist/index.mjs"; |
68 | | - let domain = ''; |
69 | | - let token = null; |
70 | 67 | const POPUP_CONFIG = { |
71 | 68 | width: 800, |
72 | 69 | height: 600, |
73 | 70 | top: 50, |
74 | 71 | left: 50, |
75 | 72 | title: "Authorize Frontify" |
76 | 73 | }; |
77 | | - |
78 | 74 | const AUTHORIZATION_CONFIG = { |
79 | | - // domain: 'weare.frontify.com', |
| 75 | + domain: 'weare.frontify.com', |
80 | 76 | clientId: 'client-65yw8hnekdg4mssd', |
81 | | - redirectUri: '/connection/frontify-authenticator', |
82 | 77 | scopes: ["basic:read", "finder:read", "account:read"], |
83 | 78 | }; |
| 79 | + |
| 80 | + let domain = ''; |
| 81 | + let token = null; |
84 | 82 |
|
85 | 83 | function authorizeAction() { |
86 | 84 | // handle domain window |
87 | 85 | if (!token) { |
88 | | - authorize(AUTHORIZATION_CONFIG, POPUP_CONFIG).then(res => { |
89 | | - console.log('initial auth'); |
90 | | - console.log(res); |
| 86 | + FrontifyAuthenticator.authorize(AUTHORIZATION_CONFIG, POPUP_CONFIG).then(res => { |
91 | 87 | if (res) { |
92 | 88 | domain = res.domain; |
93 | 89 | token = res; |
|
96 | 92 | console.log(err); |
97 | 93 | }); |
98 | 94 | } else { |
99 | | - console.log('stored auth'); |
100 | 95 | console.log(token); |
101 | 96 | } |
102 | 97 | } |
103 | 98 |
|
104 | 99 |
|
105 | 100 | function revokeAction() { |
106 | 101 | if (!token) { |
107 | | - console.log('Nothing to revoke!'); |
108 | 102 | return; |
109 | 103 | } |
110 | 104 |
|
111 | | - revoke(token).then(res => { |
112 | | - console.log('revoked token'); |
113 | | - console.log(res); |
| 105 | + FrontifyAuthenticator.revoke(token).then(res => { |
114 | 106 | token = null; |
115 | 107 | delete(AUTHORIZATION_CONFIG.domain); |
116 | 108 | }); |
117 | 109 | } |
118 | 110 |
|
119 | 111 | function refreshAction() { |
120 | 112 | if (!token) { |
121 | | - console.log('Nothing to refresh!'); |
122 | 113 | return; |
123 | 114 | } |
124 | 115 |
|
125 | | - refresh(token).then(res => { |
126 | | - console.log('refreshed token'); |
127 | | - console.log(res); |
| 116 | + FrontifyAuthenticator.refresh(token).then(res => { |
128 | 117 | token = res; |
129 | 118 | }); |
130 | 119 | } |
131 | 120 |
|
132 | 121 | document.getElementById('authorize').addEventListener('click', authorizeAction); |
133 | 122 | document.getElementById('revoke').addEventListener('click', revokeAction); |
134 | | - document.getElementById('refresh').addEventListener('click', refreshAction) |
| 123 | + document.getElementById('refresh').addEventListener('click', refreshAction); |
135 | 124 | </script> |
136 | 125 |
|
137 | 126 | </body> |
|
0 commit comments