function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rest API IntegrationRest API Integration 

How to do authentication to salesforce from java class using Rest API

Hello,

        I want to do authentication from my java client. I got Rest API which authenticate using web Application client and its working fine. But my requirement is little bit different as I need to use normal java client which will authenticate me directly to Salesforce site.

        

 

Regards,

Deepak

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

Yes, you can use the username & password flow that's part of the oauth2 support.

All Answers

Vinay BhatiaVinay Bhatia

You can pass username & password + secuirty Token to Salesforce login class and check that is valid or invalid at our java client. For this, you need to do following steps:--

 

1. Add WSDl into your java client as web reference. then it will automatically create SOAP functions into your java project.

2. call login salesforce method and pass username & password for authenticate. 

 

You will get proper session id in the response. then you are logged into salesforce.

Rest API IntegrationRest API Integration

Thanks for your reply.

               Is there any way to use REST API to authenticate login to Salesforce site in java client.

SuperfellSuperfell

Yes, you can use the username & password flow that's part of the oauth2 support.

This was selected as the best answer
Rest API IntegrationRest API Integration

Hello Simon,

 Thanks for your reply,

   

 

I tried to do this way and form once URL as

https://login.salesforce.com/services/oauth2/authorize?grant_type=password&client_id=<Clinet ID>&client_secret=<Clinet secret>&username=<My username>&password=<password + token>

 

but I am getting

HTTP/1.1 400 Bad Request
error=unsupported_response_type&error_description=response%20type%20not%20supported

as response is there any thing I am missing.

 

Regards,

Deepak

SuperfellSuperfell

The request needs to goto the token endpoint, you're using the wrong url. it shouild be /token not /authorize

hatch hozzenhatch hozzen
You can pass username & password + secuirty Token to Salesforce login class and check that is valid or invalid at our java client. For this, you need to do following steps:--
 1. Add WSDl into your java client as web  uk 49 predictions for today  (https://uk49prediction.com/)   reference. then it will automatically create SOAP functions into your java project.
2. call login salesforce method and pass username & password for authenticate. 
 You will get proper session id in the response. then you are logged into salesforce.