From 45d2bd6f3efb6ed13175fac5259e108833d2750a Mon Sep 17 00:00:00 2001 From: chauhan321 <39993408+chauhan321@users.noreply.github.com> Date: Thu, 23 May 2019 12:36:36 +0530 Subject: [PATCH] Remove Uncovered API's From OAuth2 (#849) * Remove Uncovered API's From OAuth2 Signed-off-by: kamaljeet * Removed Uncovered API's From Oauth2 solved build error --- .../Tizen.Account.OAuth2/AuthorizationResponse.cs | 33 ------- .../Tizen.Account.OAuth2/Authorizer.cs | 25 ----- .../ClientCredentialsAuthorizer.cs | 4 +- .../Tizen.Account.OAuth2/CodeGrantAuthorizer.cs | 105 +-------------------- .../ImplicitGrantAuthorizer.cs | 17 +--- .../ResourceOwnerPwdCredentialsAuthorizer.cs | 4 +- 6 files changed, 7 insertions(+), 181 deletions(-) diff --git a/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/AuthorizationResponse.cs b/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/AuthorizationResponse.cs index c12422a..c1fe528 100755 --- a/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/AuthorizationResponse.cs +++ b/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/AuthorizationResponse.cs @@ -42,39 +42,6 @@ namespace Tizen.Account.OAuth2 Dispose(false); } - /// - /// The authroization code. - /// - /// 3 - public string Code { get; internal set; } - - /// - /// The state parameter present in authorization request. - /// - /// 3 - /// - /// The value can be null depending on the server specifications. - /// - public string State { get; internal set; } - - /// - /// Custom key-value parameter received from service provider - /// - /// 3 - /// - /// The return value can be null depending on the server specifications. - /// - public string GetCustomValue(string key) - { - IntPtr value = IntPtr.Zero; - int ret = Interop.Response.GetCustomData(_responseHandle, key, out value); - if (ret != (int)OAuth2Error.None) - { - Log.Error(ErrorFactory.LogTag, "Interop failed"); - throw ErrorFactory.GetException(ret); - } - return Marshal.PtrToStringAnsi(value); - } /// /// Releases any unmanaged resources used by this object. diff --git a/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/Authorizer.cs b/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/Authorizer.cs index bf0496c..e7363dc 100755 --- a/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/Authorizer.cs +++ b/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/Authorizer.cs @@ -68,31 +68,6 @@ namespace Tizen.Account.OAuth2 } } - /// - /// Authorizes the client with access toekn / authorizaion code in Implicit and Authorization Code grant flows respectively. - /// - /// 3 - /// - /// - /// An authorization request - /// The authorization response from server - public virtual Task AuthorizeAsync(AuthorizationRequest request) - { - throw new NotImplementedException(); - } - - /// - /// Gets the access token in OAuth2 supported grant flows except Implicit Grant flow. - /// - /// 3 - /// - /// - /// A token request - /// The response from server - public virtual Task GetAccessTokenAsync(TokenRequest request) - { - throw new NotImplementedException(); - } /// /// Releases any unmanaged resources used by this object. diff --git a/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/ClientCredentialsAuthorizer.cs b/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/ClientCredentialsAuthorizer.cs index b9d8f1c..a004b8a 100755 --- a/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/ClientCredentialsAuthorizer.cs +++ b/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/ClientCredentialsAuthorizer.cs @@ -40,7 +40,7 @@ namespace Tizen.Account.OAuth2 /// /// 3 /// Thrown when the operation is not supported - public override Task AuthorizeAsync(AuthorizationRequest request) + public Task AuthorizeAsync(AuthorizationRequest request) { Log.Error(ErrorFactory.LogTag, "Authorization is not supported in this flow"); throw new InvalidOperationException(); @@ -67,7 +67,7 @@ namespace Tizen.Account.OAuth2 /// http://tizen.org/privilege/internet /// Thrown when method failed due to invalid argumets /// Thrown when method fails due to server error - public override async Task GetAccessTokenAsync(TokenRequest request) + public async Task GetAccessTokenAsync(TokenRequest request) { IntPtr requestHandle = GetRequestHandle(request as ClientCredentialsTokenRequest); return await Task.Run(() => GetAccessToken(requestHandle)); diff --git a/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/CodeGrantAuthorizer.cs b/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/CodeGrantAuthorizer.cs index bb7f1b5..6fe6467 100755 --- a/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/CodeGrantAuthorizer.cs +++ b/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/CodeGrantAuthorizer.cs @@ -36,20 +36,7 @@ namespace Tizen.Account.OAuth2 } - /// - /// Retrieves authorization code asynchronously. The authroization request parameters should be as defined in https://tools.ietf.org/html/rfc6749#section-4.1.1 - /// - /// 3 - /// The authorization request - /// The response containing authorization code. - /// http://tizen.org/privilege/internet - /// Thrown when method failed due to invalid argumets - /// Thrown when method fails due to server error - public override async Task AuthorizeAsync(AuthorizationRequest request) - { - IntPtr requestHandle = GetRequestHandle(request as CodeGrantAuthorizationRequest); - return await Task.Run(() => GetAuthorizationResponse(requestHandle)); - } + /// /// Retrieves access token by exchanging authorization code received using . @@ -61,41 +48,12 @@ namespace Tizen.Account.OAuth2 /// http://tizen.org/privilege/internet /// Thrown when method failed due to invalid argumets /// Thrown when method fails due to server error - public override async Task GetAccessTokenAsync(TokenRequest request) + public async Task GetAccessTokenAsync(TokenRequest request) { IntPtr requestHandle = GetRequestHandle(request as CodeGrantTokenRequest); return await Task.Run(() => GetAccessTokenByCode(requestHandle) ); } - /// - /// Clears the cookies - /// - /// 3 - public void ClearCookies() - { - int ret = (int)OAuth2Error.None; - ret = Interop.Manager.ClearCookies(_managerHandle); - if (ret != (int)OAuth2Error.None) - { - Log.Error(ErrorFactory.LogTag, "Interop failed"); - throw ErrorFactory.GetException(ret); - } - } - - /// - /// Clear the cache - /// - /// 3 - public void ClearCache() - { - int ret = (int)OAuth2Error.None; - ret = Interop.Manager.ClearCache(_managerHandle); - if (ret != (int)OAuth2Error.None) - { - Log.Error(ErrorFactory.LogTag, "Interop failed"); - throw ErrorFactory.GetException(ret); - } - } // Fill device request handle for Authorization code grant private IntPtr GetRequestHandle(CodeGrantAuthorizationRequest request) @@ -280,64 +238,5 @@ namespace Tizen.Account.OAuth2 return requestHandle; } - private AuthorizationResponse GetAuthorizationResponse(IntPtr requestHandle) - { - AuthorizationResponse response = null; - int ret = (int)OAuth2Error.None; - IntPtr error = IntPtr.Zero; - - Interop.Manager.Oauth2AuthGrantCallback authGrantCb = (IntPtr responseHandle, IntPtr usrData) => - { - if (responseHandle == IntPtr.Zero) - { - Log.Error(ErrorFactory.LogTag, "Error occured"); - throw (new ArgumentNullException()); - } - - Interop.Response.GetError(responseHandle, out error); - if (error == IntPtr.Zero) - { - Log.Warn(ErrorFactory.LogTag, "Error occured"); - throw ErrorFactory.GetException(error); - } - else - { - IntPtr authorizationCode; - ret = Interop.Response.GetAuthorizationCode(responseHandle, out authorizationCode); - if (ret != (int)OAuth2Error.None) - { - Log.Error(ErrorFactory.LogTag, "Interop failed"); - throw ErrorFactory.GetException(ret); - } - - IntPtr state; - ret = Interop.Response.GetState(responseHandle, out state); - if (ret != (int)OAuth2Error.None) - { - Log.Error(ErrorFactory.LogTag, "Interop failed"); - throw ErrorFactory.GetException(ret); - } - - response = new AuthorizationResponse(responseHandle) { Code = Marshal.PtrToStringAnsi(authorizationCode), State = Marshal.PtrToStringAnsi(state) }; - } - }; - - ret = Interop.Manager.RequestAuthorizationGrant(_managerHandle, requestHandle, authGrantCb, IntPtr.Zero); - Interop.Request.Destroy(requestHandle); - if (ret != (int)OAuth2Error.None || error != IntPtr.Zero) - { - if (error != IntPtr.Zero) - { - throw ErrorFactory.GetException(error); - } - else - { - Log.Error(ErrorFactory.LogTag, "Interop failed"); - throw ErrorFactory.GetException(ret); - } - } - - return response; - } } } diff --git a/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/ImplicitGrantAuthorizer.cs b/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/ImplicitGrantAuthorizer.cs index c59dbee..5e06c42 100755 --- a/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/ImplicitGrantAuthorizer.cs +++ b/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/ImplicitGrantAuthorizer.cs @@ -37,26 +37,11 @@ namespace Tizen.Account.OAuth2 } /// - /// Retrieves access token asynchronously. The authroization request parameters should be as defined in https://tools.ietf.org/html/rfc6749#section-4.2.1 - /// - /// 3 - /// The authorization request - /// The response containing access token. - /// http://tizen.org/privilege/internet - /// Thrown when method failed due to invalid argumets - /// Thrown when method fails due to server error - public new virtual async Task AuthorizeAsync(AuthorizationRequest request) - { - IntPtr requestHandle = GetRequestHandle(request as ImplicitGrantAuthorizationRequest); - return await Task.Run(() => GetAuthorizationResponse(requestHandle)); - } - - /// /// Access token can be retreived implicitly using in this flow. /// /// 3 /// Thrown when the operation is not supported - public override Task GetAccessTokenAsync(TokenRequest request) + public Task GetAccessTokenAsync(TokenRequest request) { Log.Error(ErrorFactory.LogTag, "Obtain token directly from authorization grant "); throw new InvalidOperationException(); diff --git a/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/ResourceOwnerPwdCredentialsAuthorizer.cs b/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/ResourceOwnerPwdCredentialsAuthorizer.cs index 27ae244..9cfed28 100755 --- a/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/ResourceOwnerPwdCredentialsAuthorizer.cs +++ b/src/Tizen.Account.OAuth2/Tizen.Account.OAuth2/ResourceOwnerPwdCredentialsAuthorizer.cs @@ -41,7 +41,7 @@ namespace Tizen.Account.OAuth2 /// /// 3 /// Thrown when the operation is not supported - public override Task AuthorizeAsync(AuthorizationRequest request) + public Task AuthorizeAsync(AuthorizationRequest request) { Log.Error(ErrorFactory.LogTag, "Authorization is not supported in this flow"); throw new InvalidOperationException(); @@ -57,7 +57,7 @@ namespace Tizen.Account.OAuth2 /// http://tizen.org/privilege/internet /// Thrown when method failed due to invalid argumets /// Thrown when method fails due to server error - public override async Task GetAccessTokenAsync(TokenRequest request) + public async Task GetAccessTokenAsync(TokenRequest request) { IntPtr requestHandle = GetRequestHandle(request as ResourceOwnerPwdCredentialsTokenRequest); return await Task.Run(() => GetAccessToken(requestHandle)); -- 2.7.4