teference / zoho-dotnet

Zoho API .NET SDK
MIT License
7 stars 11 forks source link

ZoHo AuthToken being replaced 1st March 2021 by OAuth #24

Open s6521d opened 3 years ago

s6521d commented 3 years ago

Are there plans to update this solution to reflect the recently announced switch from ZoHo's own authtokens to an oAuth based token system?

If there are when do you anticipate there being a beta version as we only have about 5 weeks to complete the switch over?

jsinh commented 3 years ago

@s6521d - Do you have details or link to this announcement and more details I can refer to?

While I wait for you to share more info that I can read, as far as I know - OAuth Token or Custom token - both should work in the same way - i.e. we are expected to send the token in Header as Bearer <oauth-token>

s6521d commented 3 years ago

@s6521d - Do you have details or link to this announcement and more details I can refer to?

While I wait for you to share more info that I can read, as far as I know - OAuth Token or Custom token - both should work in the same way - i.e. we are expected to send the token in Header as Bearer <oauth-token>

Here's the announcement with links to the migration process and API changes to URL and Header:

https://help.zoho.com/portal/en/community/topic/authtoken-deprecation-for-zoho-subscriptions-apis

jsinh commented 3 years ago

@s6521d Thanks for sharing. I read on it and seems like the way we add token to the HTTP client call in the code for this SDK NuGet code has not changed.

Here is are the two lines of code that does it: https://github.com/teference/zoho-dotnet/blob/master/source/Zoho.Api/Internals/InternalExtensions.cs#L47-L48

So what they are changing is how you "obtain" is token. Previously it was a fixed static token you generate from their portal vs now they are moving to OAuth based standard way of getting Access Token (and refresh token to renew your Access Token) going forward.

Note this SDK does not cover the OAuth or Legacy way of getting or generating token. As far as I know, OAuth is a standard and if Zoho has implemented it as a standard then you should be able to use any OIDC or OAuth client SDK/NuGet package to handle the part of getting a token.

Here is a NuGet that I have used in my past work: https://www.nuget.org/packages/IdentityModel.OidcClient/

Thanks!

s6521d commented 3 years ago

Hi, The code you've highlighted shows : httpClient.DefaultRequestHeaders.Add("authorization", string.Format(CultureInfo.InvariantCulture, "Zoho-authtoken {0}", authToken)); The API documentation now shows the Authorization header as:-H "Authorization: Zoho-oauthtoken 1000.41d9f2cfbd1b7a8f9e314b7aff7bc2d1.8fcc9810810a216793f385b9dd6e125f"

The header has changed from Zoho-authtoken to Zoho-oauthtoken

Kind regards,

Steve ------ Original Message ------ From: "Jaspalsinh Chauhan" notifications@github.com To: "teference/zoho-dotnet" zoho-dotnet@noreply.github.com Cc: "s6521d" s6521d@btinternet.com; "Mention" mention@noreply.github.com Sent: Monday, 25 Jan, 21 At 08:49 Subject: Re: [teference/zoho-dotnet] ZoHo AuthToken being replaced 1st March 2021 by OAuth (#24)

@s6521d https://github.com/s6521d Thanks for sharing. I read on it and seems like the way we add token to the HTTP client call in the code for this SDK NuGet code has not changed. Here is are the two lines of code that does it: https://github.com/teference/zoho-dotnet/blob/master/source/Zoho.Api/Internals/InternalExtensions.cs#L47-L48 https://github.com/teference/zoho-dotnet/blob/master/source/Zoho.Api/Internals/InternalExtensions.cs#L47-L48 So what they are changing is how you "obtain" is token. Previously it was a fixed static token you generate from their portal vs now they are moving to OAuth based standard way of getting Access Token (and refresh token to renew your Access Token) going forward. Note this SDK does not cover the OAuth or Legacy way of getting or generating token. As far as I know, OAuth is a standard and if Zoho has implemented it as a standard then you should be able to use any OIDC or OAuth client SDK/NuGet package to handle the part of getting a token. Here is a NuGet that I have used in my past work: https://www.nuget.org/packages/IdentityModel.OidcClient/ https://www.nuget.org/packages/IdentityModel.OidcClient/ Thanks! — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/teference/zoho-dotnet/issues/24#issuecomment-766655258 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AA7H7CQSTS3G4K476BCVJK3S3UWBNANCNFSM4WPZCOPQ .

s6521d commented 3 years ago

I have a workaround for this (not yet tested with a ZoHo oAuth id):

httpClient.ConfigureForZoHo( GetZoHoClient() );

Where:

GetZoHoClient is a method that creates an ZoHoClient initialised with the correct ZoHo data centre url, organization id and oAuthCode

ConfigureForZoHo is an extension to HttPClient:

using Legeris.Office365.ServiceInterface; using System.Globalization; using System.Net.Http; using Teference.Zoho.Api;

namespace Legeris.Shared.Office365 { public static class HttpClientExtensions { public static void ConfigureForZoHo(this HttpClient httpClient, ZohoClient client) { httpClient.Configure( client.Configuration.ApiBaseUrl, client.Configuration.OrganizationId, client.Configuration.AuthToken ); httpClient.DefaultRequestHeaders.Remove( "Authorization" ); httpClient.DefaultRequestHeaders.Add( "authorization", string.Format( CultureInfo.InvariantCulture, "Zoho-authtoken {0}", client.Configuration.AuthToken ) ); //httpClient.DefaultRequestHeaders.Add( "authorization", string.Format( CultureInfo.InvariantCulture, "Zoho-oauthtoken {0}", client.Configuration.AuthToken ) ); } } }