doco makes reference to OAuthLogin.GetAuthorizationCode...where is this class?

This thread is now closed to new comments.
Some of the links and information provided in this thread may no longer be available or relevant.
If you have a question please start a new post.
kjm
Trusted Cover User
160 Posts
Trusted Cover User
Australia
Trusted Cover User

160Posts

14Kudos

2Solutions

Re: doco makes reference to OAuthLogin.GetAuthorizationCode...where is this class?

Have you got the access token? @Hamishjam 

I have not used the class that was uploaded by @John_Dinning  so I cannot comment on whether it works or not but I have built my own class to get the access token

maybe that was why the class was removed from the online sample but like I said I have not tried using it..

If you have the access token then just create a SimpleOAuthKeyService and assign the values from the token to it and you should be able to run the following.  

let me know how you get on. If I have time I'll build a test harness and upload it to github for others that are stuck here...seriously considering leaving the .NET SDK and just using RestSharp/HttpClient to access the API

 

  var keystore = new SimpleOAuthKeyService();
                keystore.OAuthResponse = new OAuthTokens
                {
                    AccessToken = myobTokens.AccessToken,
                    ExpiresIn = int.Parse(myobTokens.ExpiresIn),
                    ReceivedTime = myobTokens.TokenTime,
                    RefreshToken = myobTokens.RefreshToken,
                    Scope = myobTokens.Scope,
                    TokenType = myobTokens.TokenType
                };



                // Get Company Files
                var cfService = new CompanyFileService(configuration, null, keystore);
                var companies = cfService.GetRange();

                foreach (var company in companies)
                {
                    System.Console.WriteLine(company.Name);
                    Debug.WriteLine(company.Name);
                }

 

Hamishjam
4 Posts
User

4Posts

1Kudos

0Solutions

Re: doco makes reference to OAuthLogin.GetAuthorizationCode...where is this class?

Thanks for the reply @kjm.  I have the access tokens and I'm passing them into the SimpleOAuthKeyService.OauthResponse.  That side of things is fine.  I'm just getting exceptions when trying to fetch the companyfile object with the CompanyFileService from the SDK.  I suspect there may be some unexpected json or a breaking .NET 6 change that is yet to be addressed.  My next step will be to play with it in an old .NET framework and report it via GitHub I guess.

 

I'm also leaning towards just pulling the JSON old school style but it would be nice to not have to build that out.  MYOB is MIA...  Developer site is a jungle of 404's.

kjm
Trusted Cover User
160 Posts
Trusted Cover User
Australia
Trusted Cover User

160Posts

14Kudos

2Solutions

Re: doco makes reference to OAuthLogin.GetAuthorizationCode...where is this class?

 

 

I am coding in Winforms/.NET 4.8 and it works fine but I am also leaning towards removing the .NET SDK

 

 

 

Mike_James
Ultimate Partner
5,857 Posts
Ultimate Partner
New Zealand
Ultimate Partner

5,857Posts

1,026Kudos

756Solutions

Re: doco makes reference to OAuthLogin.GetAuthorizationCode...where is this class?

Hi @kjm , there have been some recent changes to API support. For developer support, please see https://apisupport.myob.com/hc/en-us/requests/new?ticket_form_id=215283

 

The email address developers@myob.com has been retired. 

 

Also see https://apisupport.myob.com/hc/en-us/articles/5139088196751-Developer-Update-July-2022 for a summary of changes to API support. 

 

There is no specific statement around online/forum support.


Regards, Mike (mike@datawise.co.nz)
DataWise Limited (www.datawise.co.nz), developers of:
DataWise ProActive - Custom Reporting from MYOB programs
(MYOB Business, including AccountRight Live, AccountRight v19.x and exo Payroll)

Bulk download of attachments (more details...)

kjm
Trusted Cover User
160 Posts
Trusted Cover User
Australia
Trusted Cover User

160Posts

14Kudos

2Solutions

Re: doco makes reference to OAuthLogin.GetAuthorizationCode...where is this class?

 

@Mike_James  

 

thanks for the reply and links

 

 

The_Doc
Ultimate Partner
1,537 Posts
Ultimate Partner
Australia
Ultimate Partner

1,537Posts

165Kudos

162Solutions

Re: doco makes reference to OAuthLogin.GetAuthorizationCode...where is this class?

Hi @kjm 

 

Even though I am a C#.NET, VB.NET programmer I decided long ago NOT to use the SDK - just long experience with MYOB.

 

I designed my own - using MS Access VBA - and they work almost without problem - but the problem isn't usually the API. And they just work.

 

However, now I need this code in VC#.NET - hmm guess I got to go for writing my own code in C# - which shouldn't be a problem as the nitty gritty of getting it all working in VBA is long ago worked out.

 

I get very few API errors - but mainly if I do they are timeouts and I just recycle.

 

The Doc

John_Dinning
Trusted User
71 Posts
Trusted User
Australia
Trusted User

71Posts

15Kudos

6Solutions

Re: doco makes reference to OAuthLogin.GetAuthorizationCode...where is this class?

Hi kjm,

 

The OAuthLogin.cs and OAuthKeyService.cs files I posted are used in my project, which is WinForms and .NET 4.8.

It's been most of 10 years since I looked at how they work, but they have done all that time for both local, network and cloud company files.

 

It does seem odd that MYOB have not fixed the broken links and given access to these files. I'm sure it would be to their advantage. 

 

There have been times when I wished that I had not used the SDK, but it did save me a lot of time and a steep learning curve initially and it has been working fine for our purposes.

kjm
Trusted Cover User
160 Posts
Trusted Cover User
Australia
Trusted Cover User

160Posts

14Kudos

2Solutions

Re: doco makes reference to OAuthLogin.GetAuthorizationCode...where is this class?

@John_Dinning 

 

thanks for digging out those files..pretty simple stuff there..just builds a webbrowser on a form and listens to the DocumentTitleChanged event of the webrowser and then extracts the code from the document. Means that the solution has to reference Windows.Forms namespace making it a little less 'transportable' instead of just calling the users default browser. 

 

The OAuthKeyService.cs is a little more interesting as it uses IsolatedStorage to actually write the Token to a json file. This is not the path I am heading down. I would not be storing the token anywhere except memory. Not sure why or what the advantages of peristing the token like this is instead of to memory...is this incase user/system closes and then reopens and the user/system can reuse the tokens stored locally as opposed to having to make another call to oauth server? 

Anyway I have built a test harness polling the api getting data every minute and it look like the refresh token call is handeld by the SDK. I decompiled the SDK and had a look at MYOB.AccountRight.SDK.Services.ServiceBase and it looks like it handles the expiry/refresh token. Means I just have to get the token once and leave the SDK to it. Nice. Was expecting to have to handle the refresh part myself

kjm
Trusted Cover User
160 Posts
Trusted Cover User
Australia
Trusted Cover User

160Posts

14Kudos

2Solutions

Re: doco makes reference to OAuthLogin.GetAuthorizationCode...where is this class?

the more interesting point is that the SDK uses HttpWebRequest in  WebRequestFactory.cs class to make its calls.

 

Pretty sure MS are  phasing out WebRequest and will only use HttpClient...or hasnt it already been deprecated?

 

make a point for moving away from the SDK to using RestSharp or just straight HttpClientFactory to the API...seems cleaner

 

 @Hamishjam 

 

Didn't find your answer here?

Try using advanced search to find a post more easily Advanced Search
or
Get the conversation started and make a new post Start a Post