• #25872
     Rahul K Jain #218
    Forcetalks

    Can i have real-world examples for various authentication processes in Salesforce?

    Can I have real-world examples for various authentication in Salesforce like web server authentication, user agent authentication and username-password authentication?

    Tagged: , , , , , ,

    #26411
    Salesforce | Neha Neha #16
    Forcetalks

    Hi Rahul,

    Following is the example for Username-password authentication using Oauth.

    String endpoint=’https://login.salesforce.com/services/oauth2/token’;

    String username = ‘USER NAME HERE of X org’;
    String password = ‘PASSWORD without security token’;
    String ClientId= ‘connected app on Z org’;
    String ClientSecret = ‘xxxxxx’;

    Httprequest req = new HttpRequest();
    req.setMethod(‘POST’);
    req.setHeader(‘Content-Type’,’application/x-www-form-urlencoded’);

    req.setBody(‘grant_type=password’ +
    ‘&client_id=’ + ClientId +
    ‘&client_secret=’ + ClientSecret +
    ‘&username=’ + username +
    ‘&password=’ + password
    );
    req.setEndpoint(endpoint);
    Http http = new Http();
    HttpResponse res;

    try {
    res = http.send(req);
    system.debug(‘body:’+res.getBody());
    }catch(system.CalloutException e){
    system.debug(‘error’+e);
    }

    Hope this help you.!

Viewing 2 posts - 1 through 2 (of 2 total)

Please to reply to this topic.

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2018 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?