mirror of
https://github.com/ppy/osu.git
synced 2025-03-28 20:47:22 +08:00
Merge branch 'master' into general-fixes
This commit is contained in:
commit
02532e1dc8
@ -72,21 +72,28 @@ namespace osu.Game.Online.API
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static readonly object access_token_retrieval_lock = new object();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Should be run before any API request to make sure we have a valid key.
|
/// Should be run before any API request to make sure we have a valid key.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private bool ensureAccessToken()
|
private bool ensureAccessToken()
|
||||||
{
|
{
|
||||||
//todo: we need to mutex this to ensure only one authentication request is running at a time.
|
// if we already have a valid access token, let's use it.
|
||||||
|
|
||||||
//If we already have a valid access token, let's use it.
|
|
||||||
if (accessTokenValid) return true;
|
if (accessTokenValid) return true;
|
||||||
|
|
||||||
//If not, let's try using our refresh token to request a new access token.
|
// we want to ensure only a single authentication update is happening at once.
|
||||||
if (!string.IsNullOrEmpty(Token?.RefreshToken))
|
lock (access_token_retrieval_lock)
|
||||||
AuthenticateWithRefresh(Token.RefreshToken);
|
{
|
||||||
|
// re-check if valid, in case another request completed and revalidated our access.
|
||||||
|
if (accessTokenValid) return true;
|
||||||
|
|
||||||
return accessTokenValid;
|
// if not, let's try using our refresh token to request a new access token.
|
||||||
|
if (!string.IsNullOrEmpty(Token?.RefreshToken))
|
||||||
|
AuthenticateWithRefresh(Token.RefreshToken);
|
||||||
|
|
||||||
|
return accessTokenValid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool accessTokenValid => Token?.IsValid ?? false;
|
private bool accessTokenValid => Token?.IsValid ?? false;
|
||||||
|
@ -41,13 +41,13 @@ namespace osu.Game.Online.API
|
|||||||
[JsonProperty(@"refresh_token")]
|
[JsonProperty(@"refresh_token")]
|
||||||
public string RefreshToken;
|
public string RefreshToken;
|
||||||
|
|
||||||
public override string ToString() => $@"{AccessToken}/{AccessTokenExpiry.ToString(NumberFormatInfo.InvariantInfo)}/{RefreshToken}";
|
public override string ToString() => $@"{AccessToken}|{AccessTokenExpiry.ToString(NumberFormatInfo.InvariantInfo)}|{RefreshToken}";
|
||||||
|
|
||||||
public static OAuthToken Parse(string value)
|
public static OAuthToken Parse(string value)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
string[] parts = value.Split('/');
|
string[] parts = value.Split('|');
|
||||||
return new OAuthToken
|
return new OAuthToken
|
||||||
{
|
{
|
||||||
AccessToken = parts[0],
|
AccessToken = parts[0],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user