From 775b7a3fb8ed16e551b487c02e7f5e9abd13c5a4 Mon Sep 17 00:00:00 2001 From: sacOO7 <sachinshinde7676@gmail.com> Date: Mon, 15 Apr 2024 17:07:56 +0530 Subject: [PATCH] Marked old createTokenRequestObject methods as deprecated --- src/IO.Ably.Shared/AblyAuth.cs | 86 +++++++++++++++++---------------- src/IO.Ably.Shared/IAblyAuth.cs | 4 +- 2 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/IO.Ably.Shared/AblyAuth.cs b/src/IO.Ably.Shared/AblyAuth.cs index 96fda9794..67cbbc7b3 100644 --- a/src/IO.Ably.Shared/AblyAuth.cs +++ b/src/IO.Ably.Shared/AblyAuth.cs @@ -557,6 +557,11 @@ 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) { @@ -564,6 +569,13 @@ public async Task<TokenDetails> AuthoriseAsync(TokenParams tokenParams = null, A 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(); @@ -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) @@ -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)); } } } diff --git a/src/IO.Ably.Shared/IAblyAuth.cs b/src/IO.Ably.Shared/IAblyAuth.cs index cf8321ae7..a7998273e 100644 --- a/src/IO.Ably.Shared/IAblyAuth.cs +++ b/src/IO.Ably.Shared/IAblyAuth.cs @@ -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> @@ -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> @@ -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> @@ -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); } }