Skip to content
This repository has been archived by the owner on Dec 18, 2023. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/v0.3.1' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rYuuk authored Jun 2, 2023
2 parents 343d40c + a217c1e commit e06e9ce
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 23 deletions.
4 changes: 2 additions & 2 deletions Runtime/AuthManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> LoginWithCode(string otp)
Expand All @@ -60,7 +60,7 @@ public static async Task<bool> 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()
Expand Down
7 changes: 4 additions & 3 deletions Runtime/Data/AuthConstants.cs
Original file line number Diff line number Diff line change
@@ -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";
}
}
1 change: 0 additions & 1 deletion Runtime/Data/Endpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
43 changes: 27 additions & 16 deletions Runtime/WebRequests/AuthenticationRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,21 @@ public async Task<UserSession> LoginAsAnonymous()
return JsonConvert.DeserializeObject<UserSession>(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<string, string>
{
var data = new Dictionary<string, string>
{
{ 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<Response>(url, HttpMethod.POST, headers, payload);
response.ThrowIfError();
Expand All @@ -49,8 +56,8 @@ public async Task<UserSession> LoginWithCode(string code)
{
var url = GetUrl(Endpoints.AUTH_LOGIN);
var payload = AuthDataConverter.CreatePayload(new Dictionary<string, string>
{
{ AuthConstants.CODE, code }
{
{ AuthConstants.AUTH_TYPE_CODE, code }
});

var response = await webRequestDispatcher.SendRequest<Response>(url, HttpMethod.POST, headers, payload);
Expand All @@ -59,23 +66,27 @@ public async Task<UserSession> LoginWithCode(string code)
var data = AuthDataConverter.ParseResponse(response.Text);
return JsonConvert.DeserializeObject<UserSession>(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<string, string>
{
{ AuthConstants.EMAIL, email }
});
var url = GetUrl(Endpoints.AUTH_START);
var data = new Dictionary<string, string>
{
{ AuthConstants.EMAIL, email },
{ AuthConstants.AUTH_TYPE, AuthConstants.AUTH_TYPE_PASSWORD },
{ AuthConstants.USER_ID, userId }
};

var payload = AuthDataConverter.CreatePayload(data);
var response = await webRequestDispatcher.SendRequest<Response>(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<string, string>
{
{
{ AuthConstants.TOKEN, token },
{ AuthConstants.REFRESH_TOKEN, refreshToken }
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit e06e9ce

Please sign in to comment.