1

I have create a connected app and authorized in another org and get accessToken for login after that added the username and instance url of another org in custom object and with help of username and org type(production/sabdbox) it give access token and sign in through <instanceurl>/secure/frontdoor.jsp/sid=accessToken but i got error while testing this class

public class MyController{


 public MyController() {      
    Auth.JWT jwt = new Auth.JWT();
    jwt.setSub('user@salesforce.com'); 
    jwt.setAud('https://login.salesforce.com'); 
    jwt.setIss('3MVG99OxTyEMCQ3gNp2PjkqeZKxnmAiG1xV4oHh9AKL_rSK.BoSVPGZHQ​ukXnVjzRgSuQqGn75NL7yfkQcyy7');

    //Additional claims to set scope
    Map<String, Object> claims = new Map<String, Object>();
    claims.put('scope', 'scope name');

    jwt.setAdditionalClaims(claims);

    //Create the object that signs the JWT bearer token
    Auth.JWS jws = new Auth.JWS(jwt, 'CertFromCertKeyManagement');

    //Get the resulting JWS in case debugging is required
    String token = jws.getCompactSerialization();

    //Set the token endpoint that the JWT bearer token is posted to
    String tokenEndpoint = 'https://login.salesforce.com/services/oauth2/token';

    //POST the JWT bearer token
    Auth.JWTBearerTokenExchange bearer = new Auth.JWTBearerTokenExchange(tokenEndpoint, jws);

    //Get the access token
    String accessToken = bearer.getAccessToken();

} }

In this class i got null pointer on CertFromCertKeyManagement which is api name of certificate and key management self signed certificate which we upload in connected app i failed the unit test for this call ? can any one help through it ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.