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

auth: authentication.getSession doesn't respect scopes argument #1596

Open
alexweininger opened this issue Sep 21, 2023 · 9 comments · Fixed by #1597
Open

auth: authentication.getSession doesn't respect scopes argument #1596

alexweininger opened this issue Sep 21, 2023 · 9 comments · Fixed by #1597

Comments

@alexweininger
Copy link
Member

The implementation returns the same session regardless of what scopes are passed to getSession().

getSession: () => session // Rewrapped to make TS not confused about the weird initialization pattern

@alexweininger
Copy link
Member Author

alexweininger commented Jul 17, 2024

This needs to be reopened because the fix #1597 had to be reverted since it caused many downstream issues. We need to reimplement a fix for this to unblock a couple of other extensions.

See #1745

@mikeburgh
Copy link

I found a way to work around this if someone needs it while this is being worked on.

Looking at the fix, I found you can use the built in getSession method, and along with the scopes you need, add in VSCODE_TENANT:{tenantId}

For example:
vscode.authentication.getSession('microsoft',['https://management.core.windows.net/.default','VSCODE_TENANT:xxx-xxx-yyy-yyy']

The access token in the session you get back will then work with the associated API (Azure, etc) for the tenant you provided.

@scale-tone
Copy link

The same issue surfaces when using AzureSubscription.credential.getToken(scopes) method. Code:

        const provider = new VSCodeAzureSubscriptionProvider();
        const subscription = await provider.getSubscriptions(true);

        // both calls return the same token, with "aud": "https://management.core.windows.net"
        const testStorageToken = (await subscription[0].credential.getToken(['https://storage.azure.com/user_impersonation']))?.token;
        const testArmToken = (await subscription[0].credential.getToken(['https://management.core.windows.net/user_impersonation']))?.token;

@nturinski
Copy link
Member

nturinski commented Sep 27, 2024

Try this

await subscription[0].createCredentialsForScopes(['https://storage.azure.com/user_impersonation'])

@scale-tone
Copy link

@nturinski , I do not see such a method in AzureSubscription class. Where do I get that method from?

@nturinski
Copy link
Member

Sorry, you're correct. It is not something that's implemented on the AzureSubscription. You can access the method from ISubscriptionContext.

If you install the @microsoft/vscode-azext-utils package, and then call createSubscriptionContext(subscription[0]), the result object should have the method createCrednetialsForScopes.

@scale-tone
Copy link

the result object should have the method createCrednetialsForScopes.

OK, tried that, and it is even worse. That credentials.getToken() method then returns null:

image

@nturinski
Copy link
Member

How did you come across that scope? I tried the same thing and also am ending up with null. However, 'https://storage.azure.com/.default' seems to work fine for me. Would that scope suffice?

@scale-tone
Copy link

How did you come across that scope?

Oh, my memory really isn't that good, it emerged from some early days of DfMon.

Anyway, apparently @mikeburgh 's workaround worked for me, so there 's no need for further workarounds.
Thanks for your help, @nturinski !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants