Creating Microsoft Graph client for Member Login
# help-with-umbraco
s
I followed the steps in this document https://docs.umbraco.com/umbraco-cms/tutorials/add-azure-active-directory-authentication to get members logged in via Azure AD. Is there a way to get the Microsoft Graph client setup for that user once the log in? I was looking at a Microsoft example here: https://github.com/microsoftgraph/msgraph-sample-aspnet-core/blob/57bf31cc773ce9998c9deee8ccfce6e5821f1d30/GraphTutorial/Program.cs#L32 The options when you set up the Microsoft login client does not contain a value for options.Events.OnTokenValidated
I figured out a way. You can snag the access_token from the claims like so and pass it to the MS Graph SDK
Copy code
var currUser = await _memberManager.GetCurrentMemberAsync();
    var token = currUser.LoginTokens.FirstOrDefault(x => x.Name == "access_token")?.Value;
k
Access tokens have a short lifetime. Are you doing this directly after signin? Otherwise you may need to snag the
refresh_token
also.
2 Views