From 30743a5367bcdf8d394c70adead4ed9bd46a9bff Mon Sep 17 00:00:00 2001 From: Robin <1121080+rYuuk@users.noreply.github.com> Date: Fri, 2 Jun 2023 13:19:22 +0200 Subject: [PATCH 1/2] fix: add userId to account creation signup --- Runtime/AuthManager.cs | 4 +- Runtime/Data/AuthConstants.cs | 7 +-- Runtime/Data/Endpoints.cs | 1 - Runtime/WebRequests/AuthenticationRequests.cs | 43 ++++++++++++------- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/Runtime/AuthManager.cs b/Runtime/AuthManager.cs index 96cf418..8d02f49 100644 --- a/Runtime/AuthManager.cs +++ b/Runtime/AuthManager.cs @@ -39,7 +39,7 @@ public static void SetUser(UserSession session) public static async void SendEmailCode(string email) { - await AuthenticationRequests.SendCodeToEmail(email); + await AuthenticationRequests.SendCodeToEmail(email, userSession.Id); } public static async Task LoginWithCode(string otp) @@ -60,7 +60,7 @@ public static async Task LoginWithCode(string otp) public static async void Signup(string email) { - await AuthenticationRequests.Signup(email); + await AuthenticationRequests.Signup(email, userSession.Id); } public static async Task RefreshToken() diff --git a/Runtime/Data/AuthConstants.cs b/Runtime/Data/AuthConstants.cs index 5686e93..0d531fd 100644 --- a/Runtime/Data/AuthConstants.cs +++ b/Runtime/Data/AuthConstants.cs @@ -1,12 +1,13 @@ namespace ReadyPlayerMe.AvatarCreator { - public class AuthConstants + public static class AuthConstants { public const string EMAIL = "email"; public const string AUTH_TYPE = "authType"; - public const string CODE = "code"; + public const string AUTH_TYPE_CODE = "code"; + public const string AUTH_TYPE_PASSWORD = "password"; public const string TOKEN = "token"; public const string REFRESH_TOKEN = "refreshToken"; - + public const string USER_ID = "id"; } } diff --git a/Runtime/Data/Endpoints.cs b/Runtime/Data/Endpoints.cs index ec83674..9c70264 100644 --- a/Runtime/Data/Endpoints.cs +++ b/Runtime/Data/Endpoints.cs @@ -8,7 +8,6 @@ public static class Endpoints public const string AUTH_USERS = DOMAIN_URL + "/api/users"; public const string AUTH_START = DOMAIN_URL + "/api/auth/start"; public const string AUTH_LOGIN = DOMAIN_URL + "/api/auth/login"; - public const string AUTH_SIGNUP = DOMAIN_URL + "/api/auth/signup"; public const string AUTH_REFRESH = DOMAIN_URL + "/api/auth/refresh"; public const string AVATAR_API_V1 = "https://api.readyplayer.me/v1/avatars"; diff --git a/Runtime/WebRequests/AuthenticationRequests.cs b/Runtime/WebRequests/AuthenticationRequests.cs index 567daa1..a08c8d3 100644 --- a/Runtime/WebRequests/AuthenticationRequests.cs +++ b/Runtime/WebRequests/AuthenticationRequests.cs @@ -32,14 +32,21 @@ public async Task LoginAsAnonymous() return JsonConvert.DeserializeObject(data!.ToString()); } - public async Task SendCodeToEmail(string email) + public async Task SendCodeToEmail(string email, string userId = "") { var url = GetUrl(Endpoints.AUTH_START); - var payload = AuthDataConverter.CreatePayload(new Dictionary - { + var data = new Dictionary + { { AuthConstants.EMAIL, email }, - { AuthConstants.AUTH_TYPE, AuthConstants.CODE } - }); + { AuthConstants.AUTH_TYPE, AuthConstants.AUTH_TYPE_CODE }, + }; + + if (!string.IsNullOrEmpty(userId)) + { + data.Add(AuthConstants.USER_ID, userId); + } + + var payload = AuthDataConverter.CreatePayload(data); var response = await webRequestDispatcher.SendRequest(url, HttpMethod.POST, headers, payload); response.ThrowIfError(); @@ -49,8 +56,8 @@ public async Task LoginWithCode(string code) { var url = GetUrl(Endpoints.AUTH_LOGIN); var payload = AuthDataConverter.CreatePayload(new Dictionary - { - { AuthConstants.CODE, code } + { + { AuthConstants.AUTH_TYPE_CODE, code } }); var response = await webRequestDispatcher.SendRequest(url, HttpMethod.POST, headers, payload); @@ -59,23 +66,27 @@ public async Task LoginWithCode(string code) var data = AuthDataConverter.ParseResponse(response.Text); return JsonConvert.DeserializeObject(data!.ToString()); } - - public async Task Signup(string email) + + public async Task Signup(string email, string userId) { - var url = GetUrl(Endpoints.AUTH_SIGNUP); - var payload = AuthDataConverter.CreatePayload(new Dictionary - { - { AuthConstants.EMAIL, email } - }); + var url = GetUrl(Endpoints.AUTH_START); + var data = new Dictionary + { + { AuthConstants.EMAIL, email }, + { AuthConstants.AUTH_TYPE, AuthConstants.AUTH_TYPE_PASSWORD }, + { AuthConstants.USER_ID, userId } + }; + + var payload = AuthDataConverter.CreatePayload(data); var response = await webRequestDispatcher.SendRequest(url, HttpMethod.POST, headers, payload); response.ThrowIfError(); } - public async Task<(string,string)> RefreshToken(string token, string refreshToken) + public async Task<(string, string)> RefreshToken(string token, string refreshToken) { var url = GetUrl(Endpoints.AUTH_REFRESH); var payload = AuthDataConverter.CreatePayload(new Dictionary - { + { { AuthConstants.TOKEN, token }, { AuthConstants.REFRESH_TOKEN, refreshToken } }); From a217c1e950f990c18095625d066ad506d7923fe9 Mon Sep 17 00:00:00 2001 From: Robin <1121080+rYuuk@users.noreply.github.com> Date: Fri, 2 Jun 2023 13:27:19 +0200 Subject: [PATCH 2/2] feat: update version to v0.3.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9fe6dea..5851d1c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.readyplayerme.avatarcreator", - "version": "0.3.0", + "version": "0.3.1", "displayName": "Ready Player Me Avatar Creator", "description": "For creating RPM avatars in Unity", "unity": "2020.3",