From 0416a4ecb86fa00754999f335631d7024fbcac1b Mon Sep 17 00:00:00 2001 From: Quinn Purdy Date: Thu, 16 Nov 2023 08:52:36 -0500 Subject: [PATCH] Setup for social login with other providers - missing client IDs --- .../SequenceExamples/Scripts/UI/LoginPage.cs | 3 + Assets/SequenceSDK/Authentication/ILogin.cs | 26 ++++++++- .../SequenceSDK/Authentication/MockLogin.cs | 15 +++++ .../Authentication/OpenIdAuthenticator.cs | 56 ++++++++++++++++++- Assets/SequenceSDK/WaaS/WaaSLogin.cs | 18 +++++- 5 files changed, 112 insertions(+), 6 deletions(-) diff --git a/Assets/SequenceExamples/Scripts/UI/LoginPage.cs b/Assets/SequenceExamples/Scripts/UI/LoginPage.cs index 932af675..95fe281a 100644 --- a/Assets/SequenceExamples/Scripts/UI/LoginPage.cs +++ b/Assets/SequenceExamples/Scripts/UI/LoginPage.cs @@ -38,16 +38,19 @@ public void GoogleLogin() public void DiscordLogin() { Debug.Log("Discord Login"); + LoginHandler.DiscordLogin(); } public void FacebookLogin() { Debug.Log("Facebook Login"); + LoginHandler.FacebookLogin(); } public void AppleLogin() { Debug.Log("Apple Login"); + LoginHandler.AppleLogin(); } } } \ No newline at end of file diff --git a/Assets/SequenceSDK/Authentication/ILogin.cs b/Assets/SequenceSDK/Authentication/ILogin.cs index d14395e8..ebd7a88b 100644 --- a/Assets/SequenceSDK/Authentication/ILogin.cs +++ b/Assets/SequenceSDK/Authentication/ILogin.cs @@ -40,8 +40,32 @@ public interface ILogin /// Attempt to log the user in using Google login /// Emits an OnLoginSuccess event when successful /// Emits an OnLoginFailed event when unsuccessful - /// Social login nat also emit relevant events + /// Social login may also emit relevant events /// public void GoogleLogin(); + + /// + /// Attempt to log the user in using Discord login + /// Emits an OnLoginSuccess event when successful + /// Emits an OnLoginFailed event when unsuccessful + /// Social login may also emit relevant events + /// + public void DiscordLogin(); + + /// + /// Attempt to log the user in using Facebook login + /// Emits an OnLoginSuccess event when successful + /// Emits an OnLoginFailed event when unsuccessful + /// Social login may also emit relevant events + /// + public void FacebookLogin(); + + /// + /// Attempt to log the user in using Apple login + /// Emits an OnLoginSuccess event when successful + /// Emits an OnLoginFailed event when unsuccessful + /// Social login may also emit relevant events + /// + public void AppleLogin(); } } \ No newline at end of file diff --git a/Assets/SequenceSDK/Authentication/MockLogin.cs b/Assets/SequenceSDK/Authentication/MockLogin.cs index 10d3eb87..490e7e08 100644 --- a/Assets/SequenceSDK/Authentication/MockLogin.cs +++ b/Assets/SequenceSDK/Authentication/MockLogin.cs @@ -49,5 +49,20 @@ public void GoogleLogin() { throw new System.NotImplementedException(); } + + public void DiscordLogin() + { + throw new System.NotImplementedException(); + } + + public void FacebookLogin() + { + throw new System.NotImplementedException(); + } + + public void AppleLogin() + { + throw new System.NotImplementedException(); + } } } \ No newline at end of file diff --git a/Assets/SequenceSDK/Authentication/OpenIdAuthenticator.cs b/Assets/SequenceSDK/Authentication/OpenIdAuthenticator.cs index 606f843d..1ed1c9b3 100644 --- a/Assets/SequenceSDK/Authentication/OpenIdAuthenticator.cs +++ b/Assets/SequenceSDK/Authentication/OpenIdAuthenticator.cs @@ -10,7 +10,10 @@ public class OpenIdAuthenticator { public Action SignedIn; - private static readonly string ClientId = "1041613285238-6hrgdboqrjglsj583njhhseh4b1nh16n.apps.googleusercontent.com"; + private static readonly string GoogleClientId = "1041613285238-6hrgdboqrjglsj583njhhseh4b1nh16n.apps.googleusercontent.com"; + private static readonly string DiscordClientId = ""; // Todo replace + private static readonly string FacebookClientId = ""; // Todo replace + private static readonly string AppleClientId = ""; // Todo replace private static readonly string RedirectUrl = "https://3d41-142-115-54-118.ngrok-free.app/"; private readonly string _stateToken = Guid.NewGuid().ToString(); @@ -20,8 +23,7 @@ public void GoogleSignIn() { try { - string googleSignInUrl = - $"https://accounts.google.com/o/oauth2/auth?response_type=id_token&client_id={ClientId}&redirect_uri={RedirectUrl.AppendTrailingSlashIfNeeded()}&scope=openid+profile+email&state={_stateToken}&nonce={_nonce}/"; + string googleSignInUrl = GenerateSignInUrl("https://accounts.google.com/o/oauth2/auth", GoogleClientId); Application.OpenURL(googleSignInUrl); } catch (Exception e) @@ -29,6 +31,54 @@ public void GoogleSignIn() Debug.LogError($"Google sign in error: {e.Message}"); } } + + public void DiscordSignIn() + { + try + { + string discordSignInUrl = + GenerateSignInUrl("https://discord.com/api/oauth2/authorize", DiscordClientId); + Application.OpenURL(discordSignInUrl); + } + catch (Exception e) + { + Debug.LogError($"Discord sign in error: {e.Message}"); + } + } + + public void FacebookSignIn() + { + try + { + string facebookSignInUrl = + GenerateSignInUrl("https://www.facebook.com/v18.0/dialog/oauth", FacebookClientId); + Application.OpenURL(facebookSignInUrl); + } + catch (Exception e) + { + Debug.LogError($"Facebook sign in error: {e.Message}"); + } + } + + public void AppleSignIn() + { + try + { + string appleSignInUrl = + GenerateSignInUrl("https://appleid.apple.com/auth/authorize", AppleClientId); + Application.OpenURL(appleSignInUrl); + } + catch (Exception e) + { + Debug.LogError($"Apple sign in error: {e.Message}"); + } + } + + private string GenerateSignInUrl(string baseUrl, string clientId) + { + return + $"{baseUrl}?response_type=id_token&client_id={clientId}&redirect_uri={RedirectUrl.AppendTrailingSlashIfNeeded()}&scope=openid+profile+email&state={_stateToken}&nonce={_nonce}/"; + } public void PlatformSpecificSetup() { diff --git a/Assets/SequenceSDK/WaaS/WaaSLogin.cs b/Assets/SequenceSDK/WaaS/WaaSLogin.cs index 282aef26..817c4a12 100644 --- a/Assets/SequenceSDK/WaaS/WaaSLogin.cs +++ b/Assets/SequenceSDK/WaaS/WaaSLogin.cs @@ -46,13 +46,27 @@ public async Task Login(string email, string code) public void GoogleLogin() { - Debug.LogError("Google login"); _authenticator.GoogleSignIn(); } + public void DiscordLogin() + { + _authenticator.DiscordSignIn(); + } + + public void FacebookLogin() + { + _authenticator.FacebookSignIn(); + } + + public void AppleLogin() + { + _authenticator.AppleSignIn(); + } + private void OnSocialLogin(OpenIdAuthenticationResult result) { - Debug.LogError("Google Id token: " + result.IdToken); + Debug.LogError("Social login Id token: " + result.IdToken); ConnectToWaaS(result.IdToken); }