@@ -7,6 +7,7 @@ use std::{env, fmt};
77
88use bytes:: Buf ;
99use chrono:: { DateTime , Utc } ;
10+ use http:: Method ;
1011use http_body_util:: { BodyExt , Full } ;
1112use hyper:: body:: Bytes ;
1213use hyper:: Request ;
@@ -69,10 +70,26 @@ impl HttpClient {
6970 . map_err ( |err| Error :: Json ( "failed to deserialize token from response" , err) )
7071 }
7172
72- pub ( crate ) async fn request (
73- & self ,
74- req : Request < Full < Bytes > > ,
75- ) -> Result < Bytes , Error > {
73+ pub ( crate ) async fn token_info ( & self , token : & Token ) -> Result < TokenInfo , Error > {
74+ let req = Request :: builder ( )
75+ . method ( Method :: GET )
76+ . uri ( format ! (
77+ "https://oauth2.googleapis.com/tokeninfo?access_token={}" ,
78+ token. as_str( )
79+ ) )
80+ . body ( Full :: from ( Bytes :: new ( ) ) )
81+ . map_err ( |err| Error :: Other ( "failed to build HTTP request" , Box :: new ( err) ) ) ?;
82+
83+ let body = self
84+ . request ( req)
85+ . await
86+ . map_err ( |err| Error :: Other ( "failed to fetch token info" , Box :: new ( err) ) ) ?;
87+
88+ serde_json:: from_slice ( & body)
89+ . map_err ( |err| Error :: Json ( "failed to deserialize token info from response" , err) )
90+ }
91+
92+ pub ( crate ) async fn request ( & self , req : Request < Full < Bytes > > ) -> Result < Bytes , Error > {
7693 debug ! ( url = ?req. uri( ) , "requesting token" ) ;
7794 let ( parts, body) = self
7895 . inner
@@ -299,6 +316,11 @@ impl fmt::Debug for AuthorizedUserRefreshToken {
299316 }
300317}
301318
319+ #[ derive( Deserialize ) ]
320+ pub ( crate ) struct TokenInfo {
321+ pub ( crate ) email : String ,
322+ }
323+
302324/// How many times to attempt to fetch a token from the set credentials token endpoint.
303325const RETRY_COUNT : u8 = 5 ;
304326
0 commit comments