From b085bd27ed1cc2d9f53bb992c82c573dfb95cb42 Mon Sep 17 00:00:00 2001 From: Cornel Rautenbach <cornel.rautenbach@gmail.com> Date: Tue, 7 Jan 2025 08:42:14 +0200 Subject: [PATCH] More auth reusable items --- auth/social_login.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/auth/social_login.go b/auth/social_login.go index e3d770e..1d65373 100644 --- a/auth/social_login.go +++ b/auth/social_login.go @@ -9,6 +9,21 @@ import ( "google.golang.org/api/idtoken" ) +type AppleAuth struct { + Code string `json:"code"` + IDToken string `json:"id_token"` + State string `json:"state"` +} + +type SocialCredentials struct { + Google string `json:"google"` + Apple *AppleAuth `json:"apple"` +} + +type LoginResponse struct { + AccessToken string `json:"access_token"` +} + func ValidateGoogleIDToken(tokenString, clientID string) (string, error) { payload, err := idtoken.Validate(context.Background(), tokenString, clientID) if err != nil { @@ -87,3 +102,7 @@ func ExtractAppleEmailFromIDToken(idToken string) (string, error) { return string_utils.InterfaceToString(email) } + +func HasSocialCredentials(socialCredentials SocialCredentials) bool { + return socialCredentials.Google != "" || (socialCredentials.Apple != nil && socialCredentials.Apple.IDToken != "" && socialCredentials.Apple.Code != "") +} -- GitLab