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

[QUERY] Possibility to create VMs on behalf of users via Azure SDK? #44420

Open
3 tasks done
IbraAltaee opened this issue Feb 26, 2025 · 5 comments
Open
3 tasks done

[QUERY] Possibility to create VMs on behalf of users via Azure SDK? #44420

IbraAltaee opened this issue Feb 26, 2025 · 5 comments
Assignees
Labels
Azure.Identity azure-spring All azure-spring related issues customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@IbraAltaee
Copy link

IbraAltaee commented Feb 26, 2025

Query/Question
I have a web application (backend: Java Spring Boot; frontend: React NextJS) that is supposed to create VMs on behalf of users (multi-tenant & personal accounts), on their Azure account, using Azure SDK.

So a usual scenario would be: user (could be anyone) opens the website, gets prompted to login to Microsoft, then after login, fills in basic VM configurations form. Finally, the user clicks on 'Create', and the VM is created on their Azure account.

After days of reading through documentations I came to the conclusion that I could use InteractiveBrowserCredential for authentication. But I'm not quite sure whether InteractiveBrowserCredential is appropriate, and when I tried to use it, no popup was shown, and i was just authenticated, so I couldn't test it out.

Finally, I was wondering if AccessToken that is returned by MSAL, usable in a way to obtain a valid Credential to authenticate to Azure SDK.

Why is this not a Bug or a feature Request?
It's not a bug. And I'm not sure whether it's already possible, hence its not a feature request.

Setup (please complete the following information if applicable):

  • OS: Windows 11
  • IDE: VSC
  • Library/Libraries: [e.g. com.azure:azure-core:1.16.0 (groupId:artifactId:version)]

Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

  • Query Added
  • Why not a Bug or a feature request Added
  • Setup information Added
@github-actions github-actions bot added customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Feb 26, 2025
@joshfree joshfree added Azure.Identity azure-spring All azure-spring related issues labels Feb 26, 2025
@github-actions github-actions bot removed the needs-triage Workflow: This is a new issue that needs to be triaged to the appropriate team. label Feb 26, 2025
@joshfree
Copy link
Member

Hi @IbraAltaee thanks for reaching out to us via Github. @billwert can assist with some of these EntraID and Azure Identity SDK questions, and @saragluna can assist with Azure Spring related questions.

@billwert
Copy link
Contributor

Hello @IbraAltaee!

I think the confusion is coming from where you're trying to run the credential. If you're using the Java InteractiveBrowserCredential in your server, that isn't going to work. There's not a mechanism for routing the "start a browser pointed to the login page" flow from backend to frontend. If you're using it in the React app, you may have been authorized through an earlier cached login perhaps?

I think you have two options:

  1. Shift to using DeviceCodeCredential. You'd set a consumer on the DeviceCodeCredentialBuilder via challengeConsumer(Consumer<DeviceCodeInfo>). When your service client needs a token, the consumer would need to send a message to the web application to prompt the user to complete the authentication flow, presenting the verification URL and device code from the DeviceCodeInfo.
  2. Move the code doing the management tasks into your React app. Then you can use InteractiveBrowserCredential in the React app. If you go this route, I'd also migrate the management tasks you're doing into the React app and use the JS libraries for that also.

You want your management client and your credential to live on the same "side of the fence", so either frontend or backend. The client will get a token on your behalf automatically (invoking the flow of your chosen credential type.)

There may be other ways to accomplish this but I wouldn't recommend them if you can make one of these options work.

Regarding MSAL, the Azure Identity SDK is a wrapper around MSAL, so all their flows are exposed through our credential types. The benefit of the Identity SDK is that our management and service clients are built to take a credential which handles everything for you. I wouldn't recommend trying to break back down to MSAL directly - you'd just wind up wrapping whatever you got in something like our ClientAssertionCredential anyway, and would have bought yourself dealing with caching, refresh, expiry, etc.

Let me know if you have further questions.

@billwert billwert added the needs-author-feedback Workflow: More information is needed from author to address the issue. label Feb 26, 2025
Copy link
Contributor

Hi @IbraAltaee. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.

@IbraAltaee
Copy link
Author

Hi @billwert

Thanks a lot for your answer. I was actually looking into pgAdmin and how it can deploy a PostgreSQL server on the Azure Database. They too use a DeviceCodeCredential. So your reply confirmed to me it's a good approach.

Regarding InteractiveBrowserCredential, why is it a bad idea to obtain the credential in the frontend, and send it to the backend?

@github-actions github-actions bot added needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team and removed needs-author-feedback Workflow: More information is needed from author to address the issue. labels Feb 27, 2025
@IbraAltaee
Copy link
Author

For future use by others: I was actually able to obtain a TokenCredential with the access token from MSAL

TokenCredential credential = new TokenCredential() {
        @Override
        public Mono<AccessToken> getToken(TokenRequestContext tokenRequestContext) {
                return Mono.just(new AccessToken(accessToken, OffsetDateTime.now().plusHours(1)));
        }
};

But I will stick to one of the 2 Azure Identity approaches.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Identity azure-spring All azure-spring related issues customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
Status: Untriaged
Status: Todo
Development

No branches or pull requests

4 participants