Skip to content

Commit 31e3c33

Browse files
Merge pull request #2 from unity-game-framework/issue-1-add-implementation
Add implementation
2 parents f3c4c8b + 7d9a9fa commit 31e3c33

21 files changed

+455
-8
lines changed

Packages/UGF.Module.Authentication/Runtime.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using UGF.Application.Runtime;
2+
using UGF.Logs.Runtime;
3+
4+
namespace UGF.Module.Authentication.Runtime
5+
{
6+
public abstract class AuthenticationModule<TDescription> : ApplicationModuleAsync<TDescription>, IAuthenticationModule where TDescription : class, IApplicationModuleDescription
7+
{
8+
public bool IsSigned { get { return OnIsSigned(); } }
9+
10+
protected AuthenticationModule(TDescription description, IApplication application) : base(description, application)
11+
{
12+
}
13+
14+
public void SignOut()
15+
{
16+
Log.Debug("Authentication signing out.");
17+
18+
OnSignOut();
19+
}
20+
21+
protected abstract bool OnIsSigned();
22+
protected abstract void OnSignOut();
23+
}
24+
}

Packages/UGF.Module.Authentication/Runtime/AuthenticationModule.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using UGF.Application.Runtime;
2+
3+
namespace UGF.Module.Authentication.Runtime
4+
{
5+
public interface IAuthenticationModule : IApplicationModule
6+
{
7+
bool IsSigned { get; }
8+
9+
void SignOut();
10+
}
11+
}

Packages/UGF.Module.Authentication/Runtime/IAuthenticationModule.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"name": "UGF.Module.Authentication.Runtime",
3+
"rootNamespace": "UGF.Module.Authentication.Runtime",
4+
"references": [
5+
"GUID:a4312e46e9f64bb4aa011ac96ffd2a61",
6+
"GUID:6c7389a7d4bbed54e96eb1e71a69798e",
7+
"GUID:3ad3a680cb737c6428dc532d551e7bb7",
8+
"GUID:088d00b6871540e44bce58af1a3f0f17",
9+
"GUID:d067af32d09350a4bb33960432735e4d",
10+
"GUID:6ca210c6fc8b79d4292f3cdb1061c73e",
11+
"GUID:a442b1f2ca35f854f80dff74b166d9c0",
12+
"GUID:16fde9420ef50f34db61e711e19381dd",
13+
"GUID:5540e30183c82e84b954c033c388e06c",
14+
"GUID:fe25561d224ed4743af4c60938a59d0b"
15+
],
16+
"includePlatforms": [],
17+
"excludePlatforms": [],
18+
"allowUnsafeCode": false,
19+
"overrideReferences": false,
20+
"precompiledReferences": [],
21+
"autoReferenced": true,
22+
"defineConstraints": [],
23+
"versionDefines": [],
24+
"noEngineReferences": false
25+
}

Packages/UGF.Module.Authentication/Runtime/UGF.Module.Authentication.Runtime.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/UGF.Module.Authentication/Runtime/Unity.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
using System.Threading.Tasks;
2+
using UGF.Application.Runtime;
3+
using UGF.Logs.Runtime;
4+
using UGF.Module.Services.Runtime;
5+
using UGF.Module.Services.Runtime.Unity;
6+
using Unity.Services.Authentication;
7+
using Unity.Services.Core;
8+
9+
namespace UGF.Module.Authentication.Runtime.Unity
10+
{
11+
public class AuthenticationUnityModule : AuthenticationModule<AuthenticationUnityModuleDescription>
12+
{
13+
public IAuthenticationService Service { get { return AuthenticationService.Instance; } }
14+
15+
protected ServicesUnityModule ServicesUnityModule { get; }
16+
17+
public AuthenticationUnityModule(AuthenticationUnityModuleDescription description, IApplication application) : base(description, application)
18+
{
19+
ServicesUnityModule = (ServicesUnityModule)Application.GetModule<IServicesModule>();
20+
}
21+
22+
protected override void OnInitialize()
23+
{
24+
base.OnInitialize();
25+
26+
ServicesUnityModule.ConfiguringOptions += OnConfiguringOptions;
27+
}
28+
29+
protected override async Task OnInitializeAsync()
30+
{
31+
await base.OnInitializeAsync();
32+
33+
if (Description.SignAnonymouslyOnInitializeAsync)
34+
{
35+
var options = new SignInOptions
36+
{
37+
CreateAccount = Description.SignAnonymousDescription.CreateAccount
38+
};
39+
40+
Log.Debug("Authentication Unity signing anonymously.");
41+
42+
await Service.SignInAnonymouslyAsync(options);
43+
}
44+
}
45+
46+
protected override void OnUninitialize()
47+
{
48+
base.OnUninitialize();
49+
50+
ServicesUnityModule.ConfiguringOptions -= OnConfiguringOptions;
51+
}
52+
53+
protected override bool OnIsSigned()
54+
{
55+
return Service.IsSignedIn;
56+
}
57+
58+
protected override void OnSignOut()
59+
{
60+
Service.SignOut(Description.ClearCredentialsOnSignOut);
61+
62+
Log.Debug("Authentication Unity signed out", new
63+
{
64+
Description.ClearCredentialsOnSignOut
65+
});
66+
}
67+
68+
private void OnConfiguringOptions(InitializationOptions options)
69+
{
70+
if (Description.HasProfile)
71+
{
72+
options.SetProfile(Description.Profile);
73+
74+
Log.Debug("Authentication Unity setup profile", new
75+
{
76+
Description.Profile
77+
});
78+
}
79+
}
80+
}
81+
}

Packages/UGF.Module.Authentication/Runtime/Unity/AuthenticationUnityModule.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using System;
2+
using UGF.Application.Runtime;
3+
using UnityEngine;
4+
5+
namespace UGF.Module.Authentication.Runtime.Unity
6+
{
7+
[CreateAssetMenu(menuName = "Unity Game Framework/Authentication/Authentication Unity Module", order = 2000)]
8+
public class AuthenticationUnityModuleAsset : ApplicationModuleAsset<AuthenticationUnityModule, AuthenticationUnityModuleDescription>
9+
{
10+
[SerializeField] private bool m_signAnonymouslyOnInitializeAsync;
11+
[SerializeField] private AuthenticationUnitySignAnonymousData m_signAnonymousSettings;
12+
[SerializeField] private bool m_clearCredentialsOnSignOut;
13+
[SerializeField] private string m_profile;
14+
15+
public bool SignAnonymouslyOnInitializeAsync { get { return m_signAnonymouslyOnInitializeAsync; } set { m_signAnonymouslyOnInitializeAsync = value; } }
16+
public AuthenticationUnitySignAnonymousData SignAnonymousSettings { get { return m_signAnonymousSettings; } set { m_signAnonymousSettings = value; } }
17+
public bool ClearCredentialsOnSignOut { get { return m_clearCredentialsOnSignOut; } set { m_clearCredentialsOnSignOut = value; } }
18+
public string Profile { get { return m_profile; } set { m_profile = value; } }
19+
20+
[Serializable]
21+
public struct AuthenticationUnitySignAnonymousData
22+
{
23+
[SerializeField] private bool m_createAccount;
24+
25+
public bool CreateAccount { get { return m_createAccount; } set { m_createAccount = value; } }
26+
27+
public AuthenticationUnitySignAnonymousDescription GetDescription()
28+
{
29+
return new AuthenticationUnitySignAnonymousDescription(m_createAccount);
30+
}
31+
}
32+
33+
protected override IApplicationModuleDescription OnBuildDescription()
34+
{
35+
return new AuthenticationUnityModuleDescription(
36+
typeof(IAuthenticationModule),
37+
m_signAnonymouslyOnInitializeAsync,
38+
m_signAnonymousSettings.GetDescription(),
39+
m_clearCredentialsOnSignOut,
40+
m_profile
41+
);
42+
}
43+
44+
protected override AuthenticationUnityModule OnBuild(AuthenticationUnityModuleDescription description, IApplication application)
45+
{
46+
return new AuthenticationUnityModule(description, application);
47+
}
48+
}
49+
}

Packages/UGF.Module.Authentication/Runtime/Unity/AuthenticationUnityModuleAsset.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using UGF.Application.Runtime;
3+
4+
namespace UGF.Module.Authentication.Runtime.Unity
5+
{
6+
public class AuthenticationUnityModuleDescription : ApplicationModuleDescription
7+
{
8+
public bool SignAnonymouslyOnInitializeAsync { get; }
9+
public AuthenticationUnitySignAnonymousDescription SignAnonymousDescription { get; }
10+
public bool ClearCredentialsOnSignOut { get; }
11+
public string Profile { get { return HasProfile ? m_profile : throw new ArgumentException("Value not specified."); } }
12+
public bool HasProfile { get { return !string.IsNullOrEmpty(m_profile); } }
13+
14+
private readonly string m_profile;
15+
16+
public AuthenticationUnityModuleDescription(
17+
Type registerType,
18+
bool signAnonymouslyOnInitializeAsync,
19+
AuthenticationUnitySignAnonymousDescription signAnonymousDescription,
20+
bool clearCredentialsOnSignOut,
21+
string profile)
22+
{
23+
RegisterType = registerType ?? throw new ArgumentNullException(nameof(registerType));
24+
SignAnonymouslyOnInitializeAsync = signAnonymouslyOnInitializeAsync;
25+
SignAnonymousDescription = signAnonymousDescription ?? throw new ArgumentNullException(nameof(signAnonymousDescription));
26+
ClearCredentialsOnSignOut = clearCredentialsOnSignOut;
27+
m_profile = profile;
28+
}
29+
}
30+
}

Packages/UGF.Module.Authentication/Runtime/Unity/AuthenticationUnityModuleDescription.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using UGF.Description.Runtime;
2+
3+
namespace UGF.Module.Authentication.Runtime.Unity
4+
{
5+
public class AuthenticationUnitySignAnonymousDescription : DescriptionBase
6+
{
7+
public bool CreateAccount { get; }
8+
9+
public AuthenticationUnitySignAnonymousDescription(bool createAccount)
10+
{
11+
CreateAccount = createAccount;
12+
}
13+
}
14+
}

Packages/UGF.Module.Authentication/Runtime/Unity/AuthenticationUnitySignAnonymousDescription.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/UGF.Module.Authentication/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@
1818
"publishConfig": {
1919
"registry": "https://unitygameframework.jfrog.io/artifactory/api/npm/default"
2020
},
21-
"dependencies": {}
21+
"dependencies": {
22+
"com.ugf.module.services": "1.0.0-preview.1",
23+
"com.unity.services.authentication": "2.4.0"
24+
}
2225
}

Packages/UGF.Module.Authentication/package.json.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Packages/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"com.unity.ide.rider": "3.0.17",
3+
"com.unity.ide.rider": "3.0.18",
44
"com.unity.test-framework": "2.0.1-pre.18"
55
},
66
"scopedRegistries": [

0 commit comments

Comments
 (0)