Forum Discussion

demosoapuser's avatar
demosoapuser
Occasional Contributor
7 years ago
Solved

Dynamically Set client credentials

Currently, we are using Oauth2 Client Credentials Grant on our Apis. Is there a way to set or automate the values on the Authorization Profile credentials fields dynamically (ex. values from Datasour...
  • Nastya_Khovrina's avatar
    Nastya_Khovrina
    7 years ago

    Hi New2API,

     

    To change the credentials you have set in the authorization profile (for the Client Credentials Grant type) you can use the following script in the Groovy Test Step:

    import com.eviware.soapui.impl.rest.actions.oauth.OltuOAuth2ClientFacade
    import com.eviware.soapui.support.editor.inspectors.auth.TokenType
    
    def project = context.getTestCase().getTestSuite().getProject();
    def oAuthProfile = project.getAuthRepository().getEntry("YourAuthProfile");
    oAuthProfile.setClientSecret("Secret");
    oAuthProfile.setClientID("Identification");
    
    // the following code for getting new access token
    def oAuthClientFacade = new OltuOAuth2ClientFacade(TokenType.ACCESS);
    oAuthClientFacade.requestAccessToken(oAuthProfile, true);