Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] System.PlatformNotSupportedException when using AcquireTokenOnBehalfOf in Blazor Standalone WebAssembly App project #4940

Open
LALITAMITTAL18 opened this issue Sep 24, 2024 · 6 comments

Comments

@LALITAMITTAL18
Copy link

Library version used

4.64.1

.NET version

Net 8.0

Scenario

PublicClient - desktop app

Is this a new or an existing app?

None

Issue description and reproduction steps

we are creating a office add in using Blazor Standalone WebAssembly App . I get the office token and trying to exchange it using AcquireTokenOnBehalfOf but I get System.PlatformNotSupportedException when using AcquireTokenInteractive

Relevant code snippets

Get the office token =

export function getOfficeAuthTokenAsync() {
    return new Promise((resolve, reject) => {
        try {
            Office.onReady(function () {               
                const authContext = Office.context.auth;
                
                authContext.getAccessTokenAsync(function (result) {
                   
                    if (result.status === Office.AsyncResultStatus.Succeeded) {
                       
                        const token = result.value;
                        resolve(token);
                    } else {
                        
                        reject(result.error);
                    }
                });
            });     
                       
        } catch (e) {
            console.log("e: " + e);
            reject(e);
        }
    });

Exchanging it -

IConfidentialClientApplication app =  ConfidentialClientApplicationBuilder.Create("client id")
                                                   .WithClientSecret("client sercret")
                                                   .WithAuthority($"https://login.microsoftonline.com/{tenantId}")
                                                   .Build();

    var scopeDefault = new string[] {"https://graph.microsoft.com/.default"};
    var tokenResponse = await app.AcquireTokenOnBehalfOf(scopeDefault, assert).ExecuteAsync();
    return tokenResponse.AccessToken;
}

Expected behavior

I should get a token

Identity provider

Microsoft Entra ID (Work and School accounts and Personal Microsoft accounts)

Regression

No response

Solution and workarounds

No response

@LALITAMITTAL18 LALITAMITTAL18 added needs attention Delete label after triage untriaged Do not delete. Needed for Automation labels Sep 24, 2024
@LALITAMITTAL18 LALITAMITTAL18 changed the title [Bug] ystem.PlatformNotSupportedException when using AcquireTokenInteractive in Blazor Standalone WebAssembly App project [Bug] System.PlatformNotSupportedException when using AcquireTokenInteractive in Blazor Standalone WebAssembly App project Sep 24, 2024
@bgavrilMS
Copy link
Member

Hi @LALITAMITTAL18 - the blazor webassembly version uses MSAL Javascript, not MSAL .NET. Please log an issue to https://github.com/AzureAD/microsoft-authentication-library-for-js

@bgavrilMS bgavrilMS closed this as not planned Won't fix, can't repro, duplicate, stale Sep 24, 2024
@LALITAMITTAL18
Copy link
Author

LALITAMITTAL18 commented Sep 24, 2024

No I am using msal .net library. I have created a service and injected in program.cs. And calling the service in a razor component. It’s all .net code. I am just getting office add in token in js and for that I am using jsinterop and passing to my services for exchange. This is the smaple from MS on which my code is based on - https://github.com/OfficeDev/Office-Add-in-samples/tree/main/Samples/blazor-add-in/word-blazor-add-in/word-blazor-add-in

@LALITAMITTAL18
Copy link
Author

@bgavrilMS could you please open the ticket again. This is not closed. or let me know if I have to create a new ticket.

@LALITAMITTAL18 LALITAMITTAL18 changed the title [Bug] System.PlatformNotSupportedException when using AcquireTokenInteractive in Blazor Standalone WebAssembly App project [Bug] System.PlatformNotSupportedException when using AcquireTokenOnBehalfOf in Blazor Standalone WebAssembly App project Sep 25, 2024
@bgavrilMS bgavrilMS reopened this Sep 25, 2024
@bgavrilMS
Copy link
Member

@LALITAMITTAL18 - I know you're dealing with C# code only, but Blazor is just wrapping JS code behind a C# interface.

Where exactly do you call AcquireTokenInteractive?

@LALITAMITTAL18
Copy link
Author

LALITAMITTAL18 commented Sep 25, 2024

I call AcquireTokenOnBehalfOf in a class AuthenticationManager.cs and that class I inject in a razor component and use it. This whole thing work in asp.net core app with razor pages using same jsinterop. I created a teams app ang get teams token using jsinterop from js file to cs file and provide it to my authentication manager for AcquireTokenOnBehalfOf method.

@bgavrilMS
Copy link
Member

What is the full stack trace? MSAL .NET doesn't throw PlatformNotSupportedException afaik,

@bgavrilMS bgavrilMS added requires more info and removed untriaged Do not delete. Needed for Automation needs attention Delete label after triage labels Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants