feat: google oauth

This commit is contained in:
Stavros
2025-01-24 16:29:21 +02:00
parent 433e71bd50
commit d4eca52b12
4 changed files with 88 additions and 29 deletions

View File

@@ -0,0 +1,39 @@
package providers
import (
"encoding/json"
"io"
"net/http"
)
type GoogleUserinfoResponse struct {
Email string `json:"email"`
}
func GoogleScopes() []string {
return []string{"https://www.googleapis.com/auth/userinfo.email"}
}
func GetGoogleEmail(client *http.Client) (string, error) {
res, resErr := client.Get("https://www.googleapis.com/userinfo/v2/me")
if resErr != nil {
return "", resErr
}
body, bodyErr := io.ReadAll(res.Body)
if bodyErr != nil {
return "", bodyErr
}
var user GoogleUserinfoResponse
jsonErr := json.Unmarshal(body, &user)
if jsonErr != nil {
return "", jsonErr
}
return user.Email, nil
}