Office-Add-in-samples
Office-Add-in-samples copied to clipboard
Javascript exception on initial attempt at running Office-Add-in-ASPNET-SSO sample
URL of sample
URL linking to the sample that has the bug.
Describe the bug
Add displays exception on first attempt of running Office-Add-in-ASPNET-SSO
---
EXCEPTION: TypeError: Cannot read properties of undefined (reading 'getAccessToken')
---Error: Unable to add filenames to document. Unsupported Office host application: This add-in only runs on Excel, PowerPoint, or Word.
---
To Reproduce
Steps to reproduce the behavior:
- Follow client setup steps in the section Register the add-in with Microsoft identity platform at: https://learn.microsoft.com/en-us/office/dev/add-ins/develop/create-sso-office-add-ins-aspnet
- Follow run steps in the section Run the solution at https://learn.microsoft.com/en-us/office/dev/add-ins/develop/create-sso-office-add-ins-aspnet
- See error
Expected behavior
The sample to work as expected (show the list of onedrive files).
https://github.com/OfficeDev/Office-Add-in-samples/assets/17306094/40fa01a1-9f37-495a-81bc-bfab74fb5744
Environment
- Platform [PC desktop, Mac, iOS, Office Online]: PC desktop
- Host [Excel, Word, PowerPoint, etc.]: Excel (tried in Word too, same result)____
- Office version number: ______
- Operating System: ______
- Browser (if using Office Online): ______
Additional context I am testing as an identity in an organization which is not in the same organization (AD) where the Application is registered, but I presume this has no correlation to the issue (javascript error).
Hi @davidhjones,
Sorry you're encountering issues. Quick question: are you starting with the Begin or Complete version of this sample?
I am starting with the Complete version of this sample.
Hi @davidhjones,
The behavior from the browser pop-up is expected. The add-in has to be run from the task pane in Excel. I see from your video that the task pane pops up with an error. Does that consistently happen? What happens when you click "Restart" in the task pane?
One thing that may help an add-in in a bad state is clearing the cache: https://learn.microsoft.com/en-us/office/dev/add-ins/testing/clear-cache. Let us know if that gets your task pane in a workable state.
Interestingly enough, when I loaded it up this morning, the Add-in does load in the task pane. Unfortunately, now I'm getting a different error. Oddly enough, following the code I would expect that my breakpoint in FilesController would get triggered to execute the code below, but it isn't.
let accessToken = await Office.auth.getAccessToken(options);
fileNameList = await callRESTApi("/api/files", accessToken);
https://github.com/OfficeDev/Office-Add-in-samples/assets/17306094/76914917-f8bb-45ac-a15a-0a499bd200b9
I have confirmed that the exception is thrown from await Office.auth.getAccessToken(options);, which explains why my breakpoint is never triggered (on the server).
One thing to note, I have been able to make progress by switching to the Outlook add-in SSO sample. I did have issues testing with a client outside of my account’s tenant, but I believe that’s due to me not having administrative privileges to approve the Application.
Hi @davidhjones,
Sorry for the delayed response; I've been out. Since the MSAL fallback path is triggering, I'm guessing there's some piece of setup that's incorrect in Azure. Double-check the Redirect URL, authorized client applications, and scopes. A setup error would explain why the Outlook sample is working and the Excel one is not.
This issue has been automatically marked as stale because it is marked as needing author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thank you for your interest in Office Add-ins!
This issue has been closed due to inactivity. Please comment if you still need assistance and we'll re-open the issue.