Skip to content

Commit

Permalink
Merge pull request #238 from onerain88/refresh-token
Browse files Browse the repository at this point in the history
feat: refresh session token
  • Loading branch information
onerain88 authored Jan 11, 2023
2 parents 8957da8 + ad87731 commit bb6e066
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Storage/Storage.Test/UserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand Down
7 changes: 7 additions & 0 deletions Storage/Storage/Public/User/LCUser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,13 @@ public static async Task<LCUser> BecomeWithSessionToken(string sessionToken) {
return currentUser;
}

public async Task RefreshSessionToken() {
string path = $"users/{ObjectId}/refreshSessionToken";
Dictionary<string, object> response = await LCCore.HttpClient.Put<Dictionary<string, object>>(path);
SessionToken = response["sessionToken"] as string;
await _SaveToLocal();
}

/// <summary>
/// Requests a password reset email to be sent to a user's email address.
/// </summary>
Expand Down

0 comments on commit bb6e066

Please sign in to comment.