Skip to content

Commit c078d62

Browse files
authored
WF-1242 Add sample implementation of PlayerIdentityToken verification code in authentication flow example (#41)
* Add sample implementation of PlayerIdentityToken verification code required by customer side * Update README to give specific instructions for running examples in own project
1 parent 69970ca commit c078d62

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

examples/BYOAuthFlow/Program.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ namespace BYOAuthFlow
1818
/// This contains the implementation of the "Player authentication" scenario.
1919
/// 1. Start a cloud deployment.
2020
/// 2. Create a PlayerIdentityToken.
21-
/// 3. Choose a deployment that is ready for login.
22-
/// 4. Create a LoginToken for a selected deployment.
23-
/// 5. Connect to the deployment using the PlayerIdentityToken and the LoginToken.
21+
/// 3. Verify the PlayerIdentityToken.
22+
/// 4. Choose a deployment that is ready for login.
23+
/// 5. Create a LoginToken for a selected deployment.
24+
/// 6. Connect to the deployment using the PlayerIdentityToken and the LoginToken.
2425
/// </summary>
2526
internal class BYOAuthScenario : ScenarioBase
2627
{
@@ -103,6 +104,17 @@ protected override void Run()
103104
ProjectName = ProjectName
104105
});
105106

107+
Console.WriteLine("Verifying PlayerIdentityToken");
108+
var decodePlayerIdentityTokenResponse = _playerAuthServiceClient.DecodePlayerIdentityToken(
109+
new DecodePlayerIdentityTokenRequest
110+
{
111+
PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken
112+
});
113+
var playerIdentityToken = decodePlayerIdentityTokenResponse.PlayerIdentityToken;
114+
if (playerIdentityToken.Provider != "provider") throw new Exception("Provider not recognised.");
115+
if (playerIdentityToken.ProjectName != ProjectName) throw new Exception("Project not recognised.");
116+
if (DateTime.Now.CompareTo(playerIdentityToken.ExpiryTime.ToDateTime()) > 0) throw new Exception("PlayerIdentityToken expired.");
117+
106118
Console.WriteLine("Choosing a deployment");
107119
var suitableDeployment = _deploymentServiceClient.ListDeployments(new ListDeploymentsRequest
108120
{

examples/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ dotnet restore
1818
dotnet run
1919
```
2020

21+
## Running this example in your own SpatialOS project
22+
Building and uploading the assembly of this project is not required to use the example C# code for the scenarios shown here in your own project. However, if you wish to see this example in action for yourself, you can use the pre-built assembly included in this repository to run a deployment on your own SpatialOS project:
23+
24+
1. Modify the `spatialos.json` file in the `blank_project` directory to use the name of your SpatialOS project.
25+
2. Run `spatial cloud upload blank_project` from the `blank_project` directory to upload the pre-built assembly into your project.
26+
3. Modify the required fields in the `Program.cs` file of the example project in the solution you wish to run. These fields are specified in the comments of the file.
27+
4. Follow the steps to run the solution using an IDE or the .NET core CLI.
28+
2129
## Installing C# Platform SDK
2230

2331
* Please see the [SpatialOS documentation](https://docs.improbable.io/reference/latest/platform-sdk/introduction)

0 commit comments

Comments
 (0)