How to authenticate using a user's raw access token?
dumb question - but I do the authorization flow, get a user's "oauth access token" and store it. how do i authenticate the msgraphclient using that? doesnt' seem like theres an option anywhere.
essentially a duplicate of this issue: https://github.com/microsoftgraph/msgraph-sdk-java/issues/961
I would also like to know how to do this. Authentication takes place on a different device than the one using it.
Just encountered this issue as well today. I ended up creating a simple custom authentication provider that just returns the raw access token.
from azure.core.credentials import AccessToken
class RawAccessTokenProvider:
"""
A simple credential provider that returns a raw access token for use with Azure SDK clients.
"""
def __init__(self, access_token: str, expires_on: int) -> None:
self._access_token = access_token
self._expires_on = expires_on
def get_token(self, *scopes, **kwargs) -> AccessToken:
return AccessToken(self._access_token, self._expires_on)
# Usage
credentials = RawAccessTokenProvider(raw_access_token, expires_in)
client = GraphServiceClient(credentials=credentials)
me = await client.me.get()
@rau Any chance the suggestion above works for you?
It did work! Thank you very much. I would have thought that Microsoft documentation would have had this as an example.
Thanks for confirming. We'll keep this open to track that we need to add documentation for this scenario.
This was helpful, thanks @eilonmore! +1 for adding it to the documentation, I spent quite some time looking for this (and figuring out a similar implementation myself) before stumbling across this issue.
Why not implementing this directly as a credential class inside azure.identity.aio?