pub struct Google { /* private fields */ }
Implementations§
Source§impl Google
impl Google
Sourcepub fn new(appid: String, app_secret: String, callback_url: String) -> Google
pub fn new(appid: String, app_secret: String, callback_url: String) -> Google
Creates a new instance of the Google authorization client.
§Arguments
appid
- The client ID provided by Google when registering the application.app_secret
- The client secret provided by Google when registering the application.callback_url
- The URL that the user will be redirected to after authorization is complete. This URL should be an endpoint in the application that will handle the authorization code.
§Returns
Google
- A new instance of the Google authorization client.
Sourcepub fn get_redirect_url(&self) -> String
pub fn get_redirect_url(&self) -> String
Generates a URL that the user should be redirected to in order to authorize this application. This URL is the standard authorization URL for the OAuth2 flow with the Google OAuth2 provider, and includes the scopes required to fetch the user’s profile information.
Sourcepub async fn get_userinfo(
&self,
code: String,
) -> Result<UserInfo, Box<dyn Error>>
pub async fn get_userinfo( &self, code: String, ) -> Result<UserInfo, Box<dyn Error>>
Fetches and returns the user’s profile information from Google using the provided authorization code.
This function exchanges the provided authorization code for an access token and then
uses that token to request the user’s profile information from Google’s userinfo
endpoint. The user’s information is returned as a UserInfo
struct.
§Arguments
code
- AString
representing the authorization code received from Google’s OAuth2 authorization flow.
§Returns
Result<UserInfo, Box<dyn Error>>
- On success, returnsOk(UserInfo)
containing the user’s profile information. On failure, returnsErr
with an error describing what went wrong.
§Errors
This function can return an error if the authorization code exchange fails, if the
request to fetch the user’s profile information fails, or if parsing the response
into a UserInfo
struct fails.