1
1
import { PublicClientApplication } from './msal-browser-2.14.2.js' ;
2
+ import excApp , { init } from '@adobe/exc-app' ;
3
+
4
+ import { getState } from './index.js' ;
2
5
3
6
var defaultThumbnail = require ( '../no-image.png' ) ;
4
7
let accessToken ;
5
- let connectAttempts = 0 ;
6
- ( async ( ) => {
7
8
8
- const sp = {
9
- clientApp : {
10
- auth : {
11
- clientId : '2b4aa217-ddcd-4fe0-b09c-5a472764f552' ,
12
- authority : 'https://login.microsoftonline.com/fa7b1b5a-7b34-4387-94ae-d2c178decee1' ,
13
- } ,
14
- } ,
15
- login : {
16
- redirectUri : '/spauth.html' ,
17
- } ,
18
- } ;
9
+ ( async ( ) => {
19
10
20
11
// Create mask and spinner elements
21
12
const mask = document . createElement ( 'div' ) ;
@@ -34,43 +25,13 @@ let connectAttempts = 0;
34
25
const pagePath = queryParams . get ( 'pagePath' ) ;
35
26
let data = { } ;
36
27
async function connectAndFetchData ( ) {
37
- const publicClientApplication = new PublicClientApplication ( sp . clientApp ) ;
38
- const accounts = publicClientApplication . getAllAccounts ( ) ;
39
-
40
- if ( accounts . length === 0 ) {
41
- // User is not logged in, show the login popup
42
- await publicClientApplication . loginPopup ( sp . login ) ;
43
-
44
- }
45
-
46
- const account = publicClientApplication . getAllAccounts ( ) [ 0 ] ;
47
- const accessTokenRequest = {
48
- scopes : [ 'files.readwrite' , 'sites.readwrite.all' ] ,
49
- account,
50
- } ;
51
28
52
29
try {
53
- const res = await publicClientApplication . acquireTokenSilent ( accessTokenRequest ) ;
54
- accessToken = res . accessToken ;
30
+ let state = await getState ( ) ;
31
+ accessToken = state . imsToken ;
32
+
55
33
} catch ( error ) {
56
- // Acquire token silent failure, and send an interactive request
57
- if ( error . name === 'InteractionRequiredAuthError' ) {
58
- try {
59
- const res = await publicClientApplication . acquireTokenPopup ( accessTokenRequest ) ;
60
- accessToken = res . accessToken ;
61
- console . log ( accessToken ) ;
62
- } catch ( err ) {
63
- console . error ( `Cannot connect to SharePoint: ${ err . message } ` ) ;
64
- document . body . removeChild ( mask ) ;
65
- document . querySelector ( '.assets-usage-report' ) . style . display = 'block' ;
66
- return ; // Exit if token acquisition fails
67
- }
68
- } else {
69
- console . error ( 'Error acquiring token silently:' , error . message ) ;
70
- document . body . removeChild ( mask ) ;
71
- document . querySelector ( '.assets-usage-report' ) . style . display = 'block' ;
72
- return ;
73
- }
34
+ console . log ( error ) ;
74
35
}
75
36
76
37
// Proceed if we have a valid access token
0 commit comments