Skip to content

Generate access token for a Managed identity #548

Closed

Description

Bug description

I am an Azure costumer. I can't use MSAL to generate an access token for the scope of my app reg using my managed identity.

I have this setup:

  • I deployed an Azure function app that is validating access token of an Application registration. It checks that the Client has the correct role.
  • I have a compute instance that is assigned a Managed identity. I want to send a HTTP request to my azure function with an access token generated for my Managed Identity.

It might be related to #58

To Reproduce

  1. Create an app reg with a custom role
  2. Create a managed identity
  3. Assign the custom role to the managed identity
  4. Create a compute instance and assigned it the managed identity
  5. In the compute instance run:
from azure.identity import ManagedIdentityCredential
cred = ManagedIdentityCredential(client_id="<managed-identity-client-id>")
token = cred.get_token("api://<app-reg-client-id>/.default")

The code will run indefinitely

Expected behavior
After running token = cred.get_token("api://<app-reg-client-id>/.default") the token should be generated

What you see instead
image
Code is still running and no token is generated.

The MSAL Python version you are using
1.21.0

Activity

  1. rayluo commented on Apr 5, 2023

    @rayluo
    Contributor

    Hi Pierre Valentin (@pievalentin) , your code snippet is using a different library, Azure SDK for Python, so, you would want to create a similar github issue there.

    This repo here is about Microsoft Authentication Library (MSAL) for Python. MSAL Python is currently implementing Managed Identity feature. If you are interested in trying out the bleeding edge, you can follow the instruction in #480 to try it out.

  2. pievalentin commented on Apr 6, 2023

    @pievalentin
    Author

    Oh my bad. Thanks a lot for the kind and fast help Ray Luo (@rayluo). Will try what you suggested on my company laptop tomorrow morning!

  3. pievalentin commented on Apr 6, 2023

    @pievalentin
    Author

    My azureml environment is very restricted (SSL inspection), I have some trouble installing your draft PR. I am still working on it.

  4. bgavrilMS commented on Aug 17, 2023

    @bgavrilMS
    Member

    Ray Luo (@rayluo) - is this PR not merged? I though MSAL Py supports MI now. Can you please post a link to the sample and docs?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions