From ad87731254dbd8ed7961573c9be792adbd72519a Mon Sep 17 00:00:00 2001 From: leancloud-bot Date: Fri, 6 Jan 2023 10:47:33 +0800 Subject: [PATCH] feat: refresh session token --- Storage/Storage.Test/UserTest.cs | 10 ++++++++++ Storage/Storage/Public/User/LCUser.cs | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/Storage/Storage.Test/UserTest.cs b/Storage/Storage.Test/UserTest.cs index ac652d52..728316f9 100644 --- a/Storage/Storage.Test/UserTest.cs +++ b/Storage/Storage.Test/UserTest.cs @@ -320,6 +320,16 @@ public async Task QueryUser() { } } + [Test] + [Order(19)] + public async Task RefreshSessionToken() { + LCUser user = await LCUser.Login(TestPhone, TestPhone); + string oldToken = user.SessionToken; + await user.RefreshSessionToken(); + string newToken = user.SessionToken; + Assert.AreNotEqual(oldToken, newToken); + } + private string GetTestEmail() { return $"{TestPhone}@leancloud.rocks"; } diff --git a/Storage/Storage/Public/User/LCUser.cs b/Storage/Storage/Public/User/LCUser.cs index ff79eb57..b5eee2d1 100644 --- a/Storage/Storage/Public/User/LCUser.cs +++ b/Storage/Storage/Public/User/LCUser.cs @@ -438,6 +438,13 @@ public static async Task BecomeWithSessionToken(string sessionToken) { return currentUser; } + public async Task RefreshSessionToken() { + string path = $"users/{ObjectId}/refreshSessionToken"; + Dictionary response = await LCCore.HttpClient.Put>(path); + SessionToken = response["sessionToken"] as string; + await _SaveToLocal(); + } + /// /// Requests a password reset email to be sent to a user's email address. ///