Skip to content

Commit

Permalink
Setup for social login with other providers - missing client IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
BellringerQuinn committed Nov 16, 2023
1 parent 0d1bac6 commit 0416a4e
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 6 deletions.
3 changes: 3 additions & 0 deletions Assets/SequenceExamples/Scripts/UI/LoginPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
26 changes: 25 additions & 1 deletion Assets/SequenceSDK/Authentication/ILogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
/// </summary>
public void GoogleLogin();

/// <summary>
/// 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
/// </summary>
public void DiscordLogin();

/// <summary>
/// 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
/// </summary>
public void FacebookLogin();

/// <summary>
/// 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
/// </summary>
public void AppleLogin();
}
}
15 changes: 15 additions & 0 deletions Assets/SequenceSDK/Authentication/MockLogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
56 changes: 53 additions & 3 deletions Assets/SequenceSDK/Authentication/OpenIdAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ public class OpenIdAuthenticator
{
public Action<OpenIdAuthenticationResult> 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();
Expand All @@ -20,15 +23,62 @@ 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)
{
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()
{
Expand Down
18 changes: 16 additions & 2 deletions Assets/SequenceSDK/WaaS/WaaSLogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit 0416a4e

Please sign in to comment.