google icon for simplicity

This commit is contained in:
arrelin
2026-01-28 11:48:56 +03:00
parent bbd3e9c01d
commit df3495376b
4 changed files with 35 additions and 33 deletions

View File

@@ -1,7 +1,5 @@
use oauth2::{
basic::BasicClient, AuthUrl, ClientId, ClientSecret, RedirectUrl, TokenUrl,
AuthorizationCode, TokenResponse, Scope, CsrfToken,
};
use oauth2::{basic::BasicClient, AuthUrl, ClientId, ClientSecret, RedirectUrl, TokenUrl, AuthorizationCode, TokenResponse, Scope, CsrfToken, Client, StandardRevocableToken, EndpointSet, EndpointNotSet};
use oauth2::basic::{BasicErrorResponse, BasicRevocationErrorResponse, BasicTokenIntrospectionResponse, BasicTokenResponse};
use reqwest::Client as HttpClient;
use sea_orm::{DatabaseConnection, EntityTrait, ColumnTrait, QueryFilter, ActiveModelTrait, Set};
use serde::Deserialize;
@@ -34,11 +32,7 @@ impl OAuthService {
let redirect_url = std::env::var("GOOGLE_REDIRECT_URL")
.unwrap_or_else(|_| "http://localhost:8080/api/auth/google/callback".to_string());
let client = BasicClient::new(ClientId::new(client_id))
.set_client_secret(ClientSecret::new(client_secret))
.set_auth_uri(AuthUrl::new("https://accounts.google.com/o/oauth2/v2/auth".to_string()).unwrap())
.set_token_uri(TokenUrl::new("https://oauth2.googleapis.com/token".to_string()).unwrap())
.set_redirect_uri(RedirectUrl::new(redirect_url).unwrap());
let client = Self::getClient(client_id, client_secret, redirect_url);
let (auth_url, csrf_token) = client
.authorize_url(CsrfToken::new_random)
@@ -58,11 +52,7 @@ impl OAuthService {
let redirect_url = std::env::var("GOOGLE_REDIRECT_URL")
.unwrap_or_else(|_| "http://localhost:8080/api/auth/google/callback".to_string());
let client = BasicClient::new(ClientId::new(client_id))
.set_client_secret(ClientSecret::new(client_secret))
.set_auth_uri(AuthUrl::new("https://accounts.google.com/o/oauth2/v2/auth".to_string()).unwrap())
.set_token_uri(TokenUrl::new("https://oauth2.googleapis.com/token".to_string()).unwrap())
.set_redirect_uri(RedirectUrl::new(redirect_url).unwrap());
let client = Self::getClient(client_id, client_secret, redirect_url);
let http_client = oauth2::reqwest::ClientBuilder::new()
.build()
@@ -77,6 +67,23 @@ impl OAuthService {
Ok(token.access_token().secret().clone())
}
fn getClient(client_id: String, client_secret: String, redirect_url: String) -> Client<BasicErrorResponse,
BasicTokenResponse,
BasicTokenIntrospectionResponse,
StandardRevocableToken,
BasicRevocationErrorResponse,
EndpointSet,
EndpointNotSet,
EndpointNotSet,
EndpointNotSet,
EndpointSet> {
BasicClient::new(ClientId::new(client_id))
.set_client_secret(ClientSecret::new(client_secret))
.set_auth_uri(AuthUrl::new("https://accounts.google.com/o/oauth2/v2/auth".to_string()).unwrap())
.set_token_uri(TokenUrl::new("https://oauth2.googleapis.com/token".to_string()).unwrap())
.set_redirect_uri(RedirectUrl::new(redirect_url).unwrap())
}
pub async fn get_user_info(&self, access_token: &str) -> Result<GoogleUserInfo, OAuthError> {
let response = self.http_client
.get("https://www.googleapis.com/oauth2/v2/userinfo")