feat: add google login v1

This commit is contained in:
Ruben Fiszel
2022-07-25 21:15:46 +02:00
parent 9157b68a0d
commit faab4b7c42
2 changed files with 31 additions and 0 deletions
+22
View File
@@ -665,6 +665,7 @@ async fn slack_command(
pub struct UserInfo {
name: Option<String>,
company: Option<String>,
displayName: Option<String>,
}
async fn login_callback(
@@ -807,6 +808,14 @@ async fn get_email(http_client: &Client, client_name: &str, token: &str) -> erro
.email
.to_string()
}
"google" => http_get_user_info::<EmailInfo>(
http_client,
"https://www.googleapis.com/oauth2/v1/userinfo?alt=json",
token,
)
.await?
.email
.to_string(),
_ => {
return Err(error::Error::BadRequest(
"client name not recognized".to_string(),
@@ -826,6 +835,19 @@ async fn get_user_info(
"gitlab" => {
http_get_user_info(http_client, "https://gitlab.com/api/v4/user", token).await?
}
"google" => {
let google_user_info: UserInfo = http_get_user_info(
http_client,
"https://www.googleapis.com/oauth2/v1/userinfo?alt=json",
token,
)
.await?;
UserInfo {
name: google_user_info.displayName.clone(),
company: None,
displayName: google_user_info.displayName,
}
}
_ => {
return Err(error::Error::BadRequest(
"client name not recognized".to_string(),
@@ -109,6 +109,15 @@
</button></a
>
{/if}
{#if logins.includes('google')}
<a rel="external" href="/api/oauth/login/google"
><button
class="m-auto default-button bg-gray-100 mt-2 py-2 w-full text-black hover:bg-blue-300"
>Google &nbsp;
<Icon class="pb-1" data={faGitlab} scale={1.4} />
</button></a
>
{/if}
</div>
<div class="flex flex-row-reverse w-full">
<button