cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamically Set client credentials

SOLVED
demosoapuser
Occasional Contributor

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 Datasource or Properties)? Below is the screenshot of Authorization Profile:

2017-04-10_1521.png

2 ACCEPTED SOLUTIONS

Accepted Solutions
Nastya_Khovrina
Moderator

Re: Dynamically Set client credentials

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);

 



Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

nmrao
Community Hero

Re: Dynamically Set client credentials

Thank you for your interest.

 

It is progressive. You just need to keep practice, the necessity, interest, find new problems and try to solve them.

 

You may find below thread interesting :

 

https://community.smartbear.com/t5/SoapUI-Open-Source/How-to-read-and-use-SoapUI-API-for-non-Dev-peo...



Regards,
Rao.

View solution in original post

6 REPLIES 6
nmrao
Community Hero

Re: Dynamically Set client credentials

Have you tried Property Expansion?


Regards,
Rao.
New2API
Frequent Contributor

Re: Dynamically Set client credentials

Thanks nmrao for the suggestion. I was able to retrieve access token using global properties. 

I was wondering if you could help me or show some pointers (apis) to automate this using groovy? or Java script.

 

thanks!

Nastya_Khovrina
Moderator

Re: Dynamically Set client credentials

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);

 



Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️

View solution in original post

nmrao
Community Hero

Re: Dynamically Set client credentials

Thank you for your interest.

 

It is progressive. You just need to keep practice, the necessity, interest, find new problems and try to solve them.

 

You may find below thread interesting :

 

https://community.smartbear.com/t5/SoapUI-Open-Source/How-to-read-and-use-SoapUI-API-for-non-Dev-peo...



Regards,
Rao.

View solution in original post

demosoapuser
Occasional Contributor

Re: Dynamically Set client credentials

This one solved my question and I was able to set credentials dynamically on my api calls. Thank you very much. I wasn't able to reply immediately. Thank you again!

spoot99
Senior Member

Re: Dynamically Set client credentials

Hi There, 

I was looking for the exact same answer as the question listed above. Thanks a lot for the reply, it gave me direction to look further.

 

I was able to create a GroovyScript and parametrize the Auth Entry. 

 

""""

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("Name");


oAuthProfile.setClientID("client id")
oAuthProfile.setClientSecret("client secret")
oAuthProfile.setScope("scope")
oAuthProfile.setAuthorizationURI("authorization URL" )
oAuthProfile.setAccessTokenURI("AccessToken URL" )
oAuthProfile.setRedirectURI("Redirect URL" )

 

oAuthProfile.setAutomationJavaScripts(["AutomationPage1", "AutomationPage2"])

 

//Run the Entry

def oAuthClientFacade = new OltuOAuth2ClientFacade(TokenType.ACCESS);
oAuthClientFacade.requestAccessToken(oAuthProfile, true);

""""

 

Best of luck! 

 

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors