-
Notifications
You must be signed in to change notification settings - Fork 144
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
Web API Token and Refresh Token #1595
Comments
Thanks for raising this @thorby68 To help understand this better, any chance you've been able to come across the docs at this link? I believe the first example would be incorrect as it uses imports and types that do not exist in the latest version of the php sdk(v2.x.x). Any chance you can confirm the version you are using? For context, if you use the Essentially, on making a request, this method will be called and tokens cached in the $graphServiceClient = GraphServiceClient::createWithAuthenticationProvider(
GraphPhpLeagueAuthenticationProvider::createWithAccessTokenProvider(
GraphPhpLeagueAccessTokenProvider::createWithCache(
$inMemoryCache,
$tokenRequestContext,
$scopes
)
)
);
$user = $graphServiceClient->me()->get()->wait(); |
@thorby68 just for clarification, does your application require a signed-in user who's log-in session you are trying to persist? |
No! no users required, no log-in required, just API access. |
In that case you don't need to manage access tokens yourself. you can initialize a The SDK will fetch access tokens & refresh them where necessary. |
Thank you for you help. |
Many thanks, but the method you reference will me I create a new token for every request. I was hoping to use the in memory cache ensuring the token is used when valid and the refresh token is used when the token has expired? |
Each instance of the If you'd like to use this in separate processes and cache the tokens yourself you can follow the guidance here to initialize an InMemoryAccessTokenCache & get tokens from the cache to persist externally. To make a future request using the externally stored token, you can pass the token back to the SDK by instantiating a cache here follows. The SDK will refresh the token in the cache if necessary. |
Hi Gents, thank you for your support. I'm not sure what is happenning here because when i try to confirm the token is stored (a one time thing to prove all is working OK) I get an error. I'm using the following getter to get the token:
The error is returned by the InMemoryAccessTokenCache getter: getTokenWithContext, indicating the inMemoryCache is empty!
As indicated above, the error I'm receiving is "Unable to get token using context with a null cache key". This is returned from the code (in full) below:
|
UPDATE
However, when I execcute the equivalent via the SDK,
fails at:
The full code from the SDK
use Microsoft\Kiota\Authentication\Oauth\ClientCredentialContext;
|
@thorby68 to use the Further reference: |
Thank you @Ndiritu that is brilliant, thank you.
Does the php sdk have reference documentation, or how would I translate HTTP examples like "https://graph.microsoft.com/v1.0/me/drive/root/children" into their PHP equivalent? Lastly does the PHP SDK, provide a response getter and/or getter for every data field returned from the server? i.e. if I make a query like
simply using prints an object but does not seems to contain the server response, but using the Id getter returns the drive id. Is there a reponse getter, i.e. or to present a server response similar to the json respons from a HHTP
|
Hi,
I am very new to MS Graph API, but have successfully developed connectivity with other product APIs such as Xero.
I have an open item TrackingID#2410040050002672 and was advised to post a question here.
Using the PHP SDK, I am struggling with the generating a token & refresh token, then storing both in the InMemoryAccessTokenCache for later use. It is my understanding that once this method has been established, I can call the InMemoryAccessTokenCache. If the token is still valid a valid token is returned, or, if the token is expired a refresh token returned.
My setup is complete and I can get a token using postman.
I have been advised to use the following code to establish the token & refresh token, and store them InMemoryAccessTokenCache. However, this fails as it seems Microsoft\Graph\Auth\OAuth2\OAuth2Client does not exist in the SDK !
I would appreciate any help in configuring this (it's diving me mad!!).
It is also my understanding that once the token and refresh token has been established, I can use the following to establish/re-extablish the token, prior and API call to my designated endpoint ????
Honestly, it's day 4 of going in circles, please help?
Thank you
The text was updated successfully, but these errors were encountered: