Skip to content

Commit

Permalink
Marked old createTokenRequestObject methods as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Apr 15, 2024
1 parent 31b9fec commit 775b7a3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 44 deletions.
86 changes: 44 additions & 42 deletions src/IO.Ably.Shared/AblyAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,25 @@ public async Task<TokenDetails> AuthorizeAsync(TokenParams tokenParams = null, A
return CurrentToken;
}

public TokenDetails Authorize(TokenParams tokenParams = null, AuthOptions options = null)
{
return AsyncHelper.RunSync(() => AuthorizeAsync(tokenParams, options));
}

[Obsolete("This method will be removed in the future, please replace with a call to AuthorizeAsync")]
public async Task<TokenDetails> AuthoriseAsync(TokenParams tokenParams = null, AuthOptions options = null)
{
Logger.Warning("AuthoriseAsync is deprecated and will be removed in the future, please replace with a call to AuthorizeAsync");
return await AuthorizeAsync(tokenParams, options);
}

[Obsolete("This method will be removed in the future, please replace with a call to Authorize")]
public TokenDetails Authorise(TokenParams tokenParams = null, AuthOptions options = null)
{
Logger.Warning("Authorise is deprecated and will be removed in the future, please replace with a call to Authorize.");
return AsyncHelper.RunSync(() => AuthorizeAsync(tokenParams, options));
}

private void SetCurrentTokenParams(TokenParams authTokenParams)
{
CurrentTokenParams = authTokenParams.Clone();
Expand All @@ -578,31 +590,6 @@ private void SetCurrentAuthOptions(AuthOptions options)
}
}

/// <summary>
/// Create a signed token request based on known credentials
/// and the given token params. This would typically be used if creating
/// signed requests for submission by another client.
/// </summary>
/// <param name="tokenParams"><see cref="TokenParams"/>. If null a token request is generated from options passed when the client was created.</param>
/// <param name="authOptions"><see cref="AuthOptions"/>. If null the default AuthOptions are used.</param>
/// <returns>signed token request.</returns>
[Obsolete("This method will be removed in a future version, please use CreateTokenRequestObject instead")]
public async Task<TokenRequest> CreateTokenRequestObjectAsync(TokenParams tokenParams, AuthOptions authOptions)
{
authOptions = authOptions ?? CurrentAuthOptions ?? Options;
tokenParams = tokenParams ?? CurrentTokenParams ?? TokenParams.WithDefaultsApplied();

if (string.IsNullOrEmpty(authOptions.Key))
{
throw new AblyException("No key specified", ErrorCodes.InvalidCredentials, HttpStatusCode.Unauthorized);
}

await SetTokenParamsTimestamp(authOptions, tokenParams);

var apiKey = authOptions.ParseKey();
return new TokenRequest(Now).Populate(tokenParams, apiKey.KeyName, apiKey.KeySecret);
}

private TokenAuthMethod GetTokenAuthMethod()
{
if (Options.AuthCallback != null)
Expand Down Expand Up @@ -685,34 +672,49 @@ public TokenDetails RequestToken(TokenParams tokenParams = null, AuthOptions opt
return AsyncHelper.RunSync(() => RequestTokenAsync(tokenParams, options));
}

public TokenDetails Authorize(TokenParams tokenParams = null, AuthOptions options = null)
/// <summary>
/// Create a signed token request based on known credentials
/// and the given token params. This would typically be used if creating
/// signed requests for submission by another client.
/// </summary>
/// <param name="tokenParams"><see cref="TokenParams"/>. If null a token request is generated from options passed when the client was created.</param>
/// <param name="authOptions"><see cref="AuthOptions"/>. If null the default AuthOptions are used.</param>
/// <returns>signed token request.</returns>
public async Task<string> CreateTokenRequestAsync(TokenParams tokenParams, AuthOptions authOptions)
{
return AsyncHelper.RunSync(() => AuthorizeAsync(tokenParams, options));
}
authOptions = authOptions ?? CurrentAuthOptions ?? Options;
tokenParams = tokenParams ?? CurrentTokenParams ?? TokenParams.WithDefaultsApplied();

[Obsolete("This method will be removed in the future, please replace with a call to Authorize")]
public TokenDetails Authorise(TokenParams tokenParams = null, AuthOptions options = null)
{
Logger.Warning("Authorise is deprecated and will be removed in the future, please replace with a call to Authorize.");
return AsyncHelper.RunSync(() => AuthorizeAsync(tokenParams, options));
if (string.IsNullOrEmpty(authOptions.Key))
{
throw new AblyException("No key specified", ErrorCodes.InvalidCredentials, HttpStatusCode.Unauthorized);
}

await SetTokenParamsTimestamp(authOptions, tokenParams);

var apiKey = authOptions.ParseKey();
var tokenRequest = new TokenRequest(Now).Populate(tokenParams, apiKey.KeyName, apiKey.KeySecret);

return JsonHelper.Serialize(tokenRequest);
}

[Obsolete("This method will be removed in a future version, please use CreateTokenRequest instead")]
public TokenRequest CreateTokenRequestObject(TokenParams tokenParams = null, AuthOptions authOptions = null)
public string CreateTokenRequest(TokenParams tokenParams = null, AuthOptions authOptions = null)
{
Logger.Warning("CreateTokenRequest is deprecated and will be removed in the future, please use CreateTokenRequest instead");
return AsyncHelper.RunSync(() => CreateTokenRequestObjectAsync(tokenParams, authOptions));
return AsyncHelper.RunSync(() => CreateTokenRequestAsync(tokenParams, authOptions));
}

public async Task<string> CreateTokenRequestAsync(TokenParams tokenParams, AuthOptions authOptions)
[Obsolete("This method will be removed in a future version, please use CreateTokenRequestAsync instead")]
public async Task<TokenRequest> CreateTokenRequestObjectAsync(TokenParams tokenParams, AuthOptions authOptions)
{
var tokenRequest = await CreateTokenRequestObjectAsync(tokenParams, authOptions);
return JsonHelper.Serialize(tokenRequest);
Logger.Warning("CreateTokenRequestObject is deprecated and will be removed in the future, please use CreateTokenRequest instead");
var tokenRequest = await CreateTokenRequestAsync(tokenParams, authOptions);
return JsonHelper.Deserialize<TokenRequest>(tokenRequest);
}

public string CreateTokenRequest(TokenParams tokenParams = null, AuthOptions authOptions = null)
[Obsolete("This method will be removed in a future version, please use CreateTokenRequest instead")]
public TokenRequest CreateTokenRequestObject(TokenParams tokenParams = null, AuthOptions authOptions = null)
{
return AsyncHelper.RunSync(() => CreateTokenRequestAsync(tokenParams, authOptions));
return AsyncHelper.RunSync(() => CreateTokenRequestObjectAsync(tokenParams, authOptions));
}
}
}
4 changes: 2 additions & 2 deletions src/IO.Ably.Shared/IAblyAuth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public interface IAblyAuth
/// <param name="tokenParams"><see cref="TokenParams"/>. If null a token request is generated from options passed when the client was created.</param>
/// <param name="authOptions"><see cref="AuthOptions"/>. If null the default AuthOptions are used.</param>
/// <returns>serialized signed token request.</returns>
[Obsolete("This method will be removed in a future version, please use CreateTokenRequestObjectAsync instead")]
Task<string> CreateTokenRequestAsync(TokenParams tokenParams = null, AuthOptions authOptions = null);

/// <summary>
Expand All @@ -68,6 +67,7 @@ public interface IAblyAuth
/// <param name="tokenParams"><see cref="TokenParams"/>. If null a token request is generated from options passed when the client was created.</param>
/// <param name="authOptions"><see cref="AuthOptions"/>. If null the default AuthOptions are used.</param>
/// <returns>signed token request.</returns>
[Obsolete("This method will be removed in a future version, please use CreateTokenRequestObjectAsync instead")]
Task<TokenRequest> CreateTokenRequestObjectAsync(TokenParams tokenParams = null, AuthOptions authOptions = null);

/// <summary>
Expand Down Expand Up @@ -107,7 +107,6 @@ public interface IAblyAuth
/// <param name="tokenParams"><see cref="TokenParams"/>. If null a token request is generated from options passed when the client was created.</param>
/// <param name="authOptions"><see cref="AuthOptions"/>. If null the default AuthOptions are used.</param>
/// <returns>serialized signed token request.</returns>
[Obsolete("This method will be removed in a future version, please use CreateTokenRequestObject instead")]
string CreateTokenRequest(TokenParams tokenParams = null, AuthOptions authOptions = null);

/// <summary>
Expand All @@ -117,6 +116,7 @@ public interface IAblyAuth
/// <param name="tokenParams"><see cref="TokenParams"/>. If null a token request is generated from options passed when the client was created.</param>
/// <param name="authOptions"><see cref="AuthOptions"/>. If null the default AuthOptions are used.</param>
/// <returns>signed token request.</returns>
[Obsolete("This method will be removed in a future version, please use CreateTokenRequestObject instead")]
TokenRequest CreateTokenRequestObject(TokenParams tokenParams = null, AuthOptions authOptions = null);
}
}

0 comments on commit 775b7a3

Please sign in to comment.