Jump to content
Lars Fosdal

OAuth2 bearer token example?

Recommended Posts

I am stumped.

 

I can't convince the Delphi TRESTClient to connect to a system using OAuth2 authentication.  

Either it is a about a parameterization mistake, or it is a functional failure.

 

I can't get it to work with the REST debugger either.

 

Any examples (Other than the RESTdemo) would be appreciated!

 

I have C# code that uses the same creds, and it has no issues.

I get access to the system using the Authentication URL with the clientid + clientsecret

I request a token through a different URL

I call the API URL, using the token

 

 

Share this post


Link to post

The authentication can be implemented in severeal ways. I would sniff the traffic and see the difference oooooor read the manual.

 

Usually there are some "postman" (Application) examples.

Edited by Attila Kovacs

Share this post


Link to post

I have instrumented the C# app with logging, so I see exactly what happens.

The challenge is convincing the Delphi REST components to do the same thing.

Share this post


Link to post

It is possible that you have to implement it yourself in the way it is needed as it is noted in the docs:

Quote

TOAuth2Authenticator implements a basic OAuth2 authentication. TOAuth2Authenticator offers minimal support and provides the infrastructure to follow the workflow of the service provider.

Inherit from this class to create an authenticator class specific to a service provider.

That said, giving a concrete example is difficult without knowing more details.

  • Thanks 1

Share this post


Link to post

OAuth2 is the authentication protocol. How the credentials are exchanged is up to the service provider. There are some common ways like pass it in the URL (RESTDebugger) or pass it in the headers, pass it in a JSON Object etc... The service provider will give you the documentation and examples.

Share this post


Link to post

I think I was fooled by my own expectations with regards to the simplicity of OAuth2 and functional level of the TOAuth2Authenticator.

 

The C# code example can be found here, but it uses another assembly from Thinktecture to do the http parts.

https://github.com/LarsFosdal/csharp-ion-api-sdk/blob/master/DotNetBackendOAuth2/Program.cs

 

I'll ponder a little, google some more, and see if I can't crack this nut.

 

Share this post


Link to post

I ended up writing a small class around THTTPClient from System.Net.HttpClient.

No need for the humongous REST.* classes.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×