-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
76 lines (65 loc) · 2.33 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (c) 2023 AccelByte Inc. All Rights Reserved.
// This is licensed software from AccelByte Inc, for limitations
// and restrictions contact your company contract manager.
using System;
using System.Collections.Generic;
using AccelByte.Sdk.Core;
using AccelByte.Sdk.Api;
using AccelByte.Sdk.Api.Legal.Model;
using AccelByte.Sdk.Core.Repository;
using System.Threading;
namespace AccelByte.Sdk.Sample.OnDemandTokenRefresh
{
internal class Program
{
static int Main(string[] args)
{
DefaultTokenRepository tokenRepo = new DefaultTokenRepository();
using AccelByteSDK sdk = AccelByteSDK.Builder
.UseDefaultHttpClient()
.UseDefaultConfigRepository()
.SetTokenRepository(tokenRepo)
.UseDefaultCredentialRepository()
.UseRefreshIfPossible()
.SetOnAfterLoginAction((loginType, authAction, token, sdk) =>
{
tokenRepo.SetTokenExpiry(5); //force token expire in 5s for testing purpose.
Console.WriteLine($"-> {loginType} login, action: {authAction}");
})
.Build();
int loop = 0;
int maxLoop = 100;
while (loop < maxLoop)
{
bool login = sdk.LoginUser();
if (!login)
{
Console.WriteLine("Login failed");
return 1;
}
try
{
List<RetrieveAcceptedAgreementResponse>? response = sdk.Legal.Agreement.RetrieveAgreementsPublicOp.Execute();
if (response == null)
throw new Exception("Response is null");
foreach (var aggreement in response)
Console.WriteLine(aggreement.PolicyName);
}
catch (HttpResponseException e)
{
Console.WriteLine(e.Message);
return 2;
}
Thread.Sleep(2000); //wait for 2s.
loop++;
}
bool logout = sdk.Logout();
if (!logout)
{
Console.WriteLine("Logout failed");
return 1;
}
return 0;
}
}
}