@@ -1460,6 +1460,134 @@ public static void RefreshMetaSession(string refresh_token, Action<LootLockerMet
1460
1460
) ;
1461
1461
}
1462
1462
1463
+ /// <summary>
1464
+ /// Start a Discord session.
1465
+ /// The Discord platform must be enabled and configured in the web console for this to work.
1466
+ /// A game can support multiple platforms, but it is recommended that a build only supports one platform.
1467
+ /// </summary>
1468
+ /// <param name="accessToken">The player's Discord OAuth token</param>
1469
+ /// <param name="onComplete">onComplete Action for handling the response</param>
1470
+ public static void StartDiscordSession ( string accessToken , Action < LootLockerDiscordSessionResponse > onComplete )
1471
+ {
1472
+ if ( ! CheckInitialized ( true ) )
1473
+ {
1474
+ onComplete ? . Invoke ( null ) ;
1475
+ return ;
1476
+ }
1477
+
1478
+ LootLockerServerRequest . CallAPI ( null ,
1479
+ LootLockerEndPoints . discordSessionRequest . endPoint ,
1480
+ LootLockerEndPoints . discordSessionRequest . httpMethod ,
1481
+ LootLockerJson . SerializeObject ( new LootLockerDiscordSessionRequest ( accessToken ) ) ,
1482
+ ( serverResponse ) =>
1483
+ {
1484
+ var response = LootLockerResponse . Deserialize < LootLockerDiscordSessionResponse > ( serverResponse ) ;
1485
+ if ( response . success )
1486
+ {
1487
+ LootLockerStateData . SetPlayerData ( new LootLockerPlayerData
1488
+ {
1489
+ SessionToken = response . session_token ,
1490
+ RefreshToken = response . refresh_token ,
1491
+ ULID = response . player_ulid ,
1492
+ Identifier = "" ,
1493
+ PublicUID = response . public_uid ,
1494
+ LegacyID = response . player_id ,
1495
+ Name = response . player_name ,
1496
+ WhiteLabelEmail = "" ,
1497
+ WhiteLabelToken = "" ,
1498
+ CurrentPlatform = LootLockerAuthPlatform . GetPlatformRepresentation ( LL_AuthPlatforms . Discord ) ,
1499
+ LastSignIn = DateTime . Now ,
1500
+ CreatedAt = response . player_created_at ,
1501
+ WalletID = response . wallet_id ,
1502
+ } ) ;
1503
+ }
1504
+
1505
+ onComplete ? . Invoke ( response ) ;
1506
+ } ,
1507
+ false
1508
+ ) ;
1509
+ }
1510
+
1511
+ /// <summary>
1512
+ /// Refresh a previous Discord session
1513
+ /// A response code of 400 (Bad request) could mean that the refresh token has expired and you'll need to sign in again
1514
+ /// The Discord platform must be enabled and configured in the web console for this to work.
1515
+ /// </summary>
1516
+ /// <param name="onComplete">onComplete Action for handling the response</param>
1517
+ /// <param name="forPlayerWithUlid">Optional : Execute the request for the specified player. If not supplied, the default player will be used.</param>
1518
+ public static void RefreshDiscordSession ( Action < LootLockerDiscordSessionResponse > onComplete , string forPlayerWithUlid = null )
1519
+ {
1520
+ var playerData = LootLockerStateData . GetStateForPlayerOrDefaultStateOrEmpty ( forPlayerWithUlid ) ;
1521
+ if ( string . IsNullOrEmpty ( playerData ? . RefreshToken ) )
1522
+ {
1523
+ onComplete ? . Invoke ( LootLockerResponseFactory . TokenExpiredError < LootLockerDiscordSessionResponse > ( playerData ? . ULID ) ) ;
1524
+ return ;
1525
+ }
1526
+
1527
+ RefreshDiscordSession ( playerData . RefreshToken , onComplete , forPlayerWithUlid ) ;
1528
+ }
1529
+
1530
+ /// <summary>
1531
+ /// Refresh a previous Discord session
1532
+ /// If you do not want to manually handle the refresh token we recommend using the RefreshDiscordSession(Action<LootLockerDiscordSessionResponse> onComplete, string forPlayerWithUlid) method.
1533
+ /// A response code of 400 (Bad request) could mean that the refresh token has expired and you'll need to sign in again
1534
+ /// The Discord platform must be enabled and configured in the web console for this to work.
1535
+ /// </summary>
1536
+ /// <param name="refresh_token">Token received in response from StartDiscordSession request</param>
1537
+ /// <param name="onComplete">onComplete Action for handling the response of type LootLockerDiscordSessionResponse</param>
1538
+ /// <param name="forPlayerWithUlid">Optional : Execute the request for the specified player. If not supplied, the default player will be used.</param>
1539
+ public static void RefreshDiscordSession ( string refresh_token , Action < LootLockerDiscordSessionResponse > onComplete , string forPlayerWithUlid = null )
1540
+ {
1541
+ if ( ! CheckInitialized ( true ) )
1542
+ {
1543
+ onComplete ? . Invoke ( LootLockerResponseFactory . SDKNotInitializedError < LootLockerDiscordSessionResponse > ( forPlayerWithUlid ) ) ;
1544
+ return ;
1545
+ }
1546
+
1547
+ if ( string . IsNullOrEmpty ( refresh_token ) )
1548
+ {
1549
+ var playerData = LootLockerStateData . GetStateForPlayerOrDefaultStateOrEmpty ( forPlayerWithUlid ) ;
1550
+ if ( string . IsNullOrEmpty ( playerData ? . RefreshToken ) )
1551
+ {
1552
+ onComplete ? . Invoke ( LootLockerResponseFactory . TokenExpiredError < LootLockerDiscordSessionResponse > ( playerData ? . ULID ) ) ;
1553
+ return ;
1554
+ }
1555
+ refresh_token = playerData . RefreshToken ;
1556
+ forPlayerWithUlid = playerData . ULID ;
1557
+ }
1558
+
1559
+ LootLockerServerRequest . CallAPI ( forPlayerWithUlid ,
1560
+ LootLockerEndPoints . discordSessionRequest . endPoint , LootLockerEndPoints . discordSessionRequest . httpMethod ,
1561
+ LootLockerJson . SerializeObject ( new LootLockerDiscordRefreshSessionRequest ( refresh_token ) ) ,
1562
+ ( serverResponse ) =>
1563
+ {
1564
+ var response = LootLockerResponse . Deserialize < LootLockerDiscordSessionResponse > ( serverResponse ) ;
1565
+ if ( response . success )
1566
+ {
1567
+ LootLockerStateData . SetPlayerData ( new LootLockerPlayerData
1568
+ {
1569
+ SessionToken = response . session_token ,
1570
+ RefreshToken = response . refresh_token ,
1571
+ ULID = response . player_ulid ,
1572
+ Identifier = "" ,
1573
+ PublicUID = response . public_uid ,
1574
+ LegacyID = response . player_id ,
1575
+ Name = response . player_name ,
1576
+ WhiteLabelEmail = "" ,
1577
+ WhiteLabelToken = "" ,
1578
+ CurrentPlatform = LootLockerAuthPlatform . GetPlatformRepresentation ( LL_AuthPlatforms . Discord ) ,
1579
+ LastSignIn = DateTime . Now ,
1580
+ CreatedAt = response . player_created_at ,
1581
+ WalletID = response . wallet_id ,
1582
+ } ) ;
1583
+ }
1584
+
1585
+ onComplete ? . Invoke ( response ) ;
1586
+ } ,
1587
+ false
1588
+ ) ;
1589
+ }
1590
+
1463
1591
/// <summary>
1464
1592
/// End active session (if any exists)
1465
1593
/// Succeeds if a session was ended or no sessions were active
0 commit comments