Conversation
|
@Ndiritu, thanks for the update. I have tested the solution and was able to obtain the |
|
@daverdalas when using the assertion to initialize the GraphServiceClient, you can add the For future requests, you can re-use the cached token by passing them to the GraphServiceClient again like this. If the token has already expired at this point, the refresh token will be used by the SDK to renew the access token without requiring the user to log in. |
|
@Ndiritu Thanks for the quick reply :) I was able to get the api up and running with the help of more or less code like this: $authorizationCodeContext = new AuthorizationCodeContext(
tenantId: $tenantId,
clientId: $clientId,
clientSecret: $clientSecret,
authCode: $authCode,
redirectUri: $redirectUri
);
$tokenProvider = new GraphPhpLeagueAccessTokenProvider(
tokenRequestContext: $authorizationCodeContext,
scopes: $scopes,
);
$tokenProvider->getAuthorizationTokenAsync(NationalCloud::GLOBAL)
->wait();
$accessToken = $tokenProvider->getAccessTokenCache()
->getAccessToken($authorizationCodeContext->getCacheKey());
$tokenRequestContext = new OnBehalfOfContext(
tenantId: $tenantId,
clientId: $clientId,
clientSecret: $clientSecret,
assertion: $accessToken,
);
$cache = new InMemoryAccessTokenCache(
tokenRequestContext: $tokenRequestContext,
accessToken: new AccessToken(
[
'access_token' => $accessToken,
'refresh_token' => $refreshToken,
// 'expires' => 1 -> Removed, no matter what value I put here the token is not refreshed and I get a message that it has expired.
]
)
);
$graphServiceClient = GraphServiceClient::createWithAuthenticationProvider(
GraphPhpLeagueAuthenticationProvider::createWithAccessTokenProvider(
GraphPhpLeagueAccessTokenProvider::createWithCache(
accessTokenCache: $cache,
tokenRequestContext: $tokenRequestContext,
scopes: $scopes,
)
)
);Too bad there is no easy way to initialize |
Updates guidance on on-behalf-of flow.
Previous description insinuated that an access token for Microsoft Graph could be re-used as an assertion, however this leads to an
invalid_granterror when the same token is used as theassertionin the on-behalf-of flow.On-behalf-of flow expects the initial access token issued to have an audience (
aud) claim of the intermediary API then the intermediary can exchange the assertion for a Microsoft Graph access token.This PR updates the description to reflect this better & links to various resources.
Azure Identity docs are not very clear about setting this up.
closes #1472
closes #1607
Microsoft Reviewers: Open in CodeFlow