Obtaning new access token using stored refresh token #441
Replies: 1 comment 1 reply
-
So I think whats happening here is that you have to set the refresh token in the OAuth instance in order to request a new access token and then call the refresh_token() method. Ive been working on making it simpler to use but its still in progress right now. Hopefully in the next release this will be much easier to use and you wont have to do as much. But essentially right now what you would have to do is: // Assume access_token is your first AccessToken object that has both an access token and refresh token you got from the
// first device code call to request a token.
let access_token = AccessToken::default();
// Get the oauth client you using. Assume get_ouath() is gonna return OAuth instance.
let mut oauth = get_oauth();
// Set the AccessToken in the client.
oauth.access_token(access_token);
// Get your handler for device code.
let mut handler = oauth.build_async().device_code();
// Call the refresh_token() method.
// This returns the new access token using the refresh token.
let response = handler.refresh_token().send().await?; Since your using serde_json::Value to get your token vs the AccessToken object in the library. You can set the AccessToken in the oauth instance by either converting serde_json::Value to AccessToken or by creating a new AccessToken and just setting the refresh token inside the AccessToken. https://github.com/sreeise/graph-rs-sdk/blob/master/graph-oauth/src/access_token.rs In future updates you won't have to use AccessToken - actually you wont' really use any of this because the future update is gonna be much different and easier to use. But it can take a while to do it as this is something I do outside of my regular job. Im hoping in the next couple of months to have it done. Let me know if you want some help using AccessToken or just have any other questions. |
Beta Was this translation helpful? Give feedback.
-
Hi everyone!
Disclaimer: I have not been working with Rust for a very long time and I am only a hobbyist.
That being said, I am trying to move some of my code from Python to Rust and one of the libraries I use heavily is the msal-sdk one.
With the Python version I am able to cache - on disk - the token obtained through a device code flow. This is taken care of automagically for me. It seems that this is something that will be coming to the sdk but I am happy to manage it myself at the moment.
I am currently saving the token on disk and reusing it to make queries successfully until the token expires.
The issue I have is that I can't seem to request a new token by using the refresh_token.
I have tried to piece together the logic from the examples by adding the access_token first, then device_code, one at a time, both of them, in a different order after the handler instantiation etc.
I keep getting the same error:
Not sure I am doing everything in the correct order as I don't know enough about Rust to be able to track the logic of how the parameters are set but it seems like I am not setting the device_code parameter at the correct time or it's not being sent in the request.
I could be completely of base here but I would really appreciate a bit of help.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions