async-oauth2 icon indicating copy to clipboard operation
async-oauth2 copied to clipboard

I don't understand how to use token

Open vporton opened this issue 3 years ago • 3 comments

I obtained a token:

        let token = client.exchange_client_credentials()
            .with_client(&reqwest_client)
            .execute::<StandardToken>().await.unwrap(); // FIXME: unwrap()

Now I don't understand how to use it to make a Reqwest request.

You should provide documentation and an example.

vporton avatar Mar 15 '22 03:03 vporton

It depends on the service, with for example Twitch you send a Authorization: Bearer <token> header for each request.

udoprog avatar Mar 15 '22 04:03 udoprog

I meant to ask a different thing:

How do I convert the token to string that goes after Bearer?

vporton avatar Mar 15 '22 05:03 vporton

You get the access token through Token::access_token which derefs to str, so it can be used as a string.

So like this:

use oauth2::Token;

let token = /*  */;

println!("{}", token.access_token());
let token_as_string = token.access_token().to_string();

udoprog avatar Mar 15 '22 05:03 udoprog