Forum Discussion

bpistole's avatar
bpistole
Contributor
7 years ago

How to Select Auth method during run time

I've got a project that needs to run in several different Azure environments.  Each one has it's own authorization profile.  I need to be able to set this value based on the test environment.  Has anyone dealt with this

 

Conversly I could also possible populate the auth profile values based on the env.  I could just store the tenant, secret, resource values and create the profile at run time.  I'm not sure if this is even feasible but just trying to think of options.

 

Thanks,

Billy

 

  • I have very rarely had to dynamically change the auth profile. This can be achived by the following Groovy Script:

     

    testRunner.getTestCase().getTestStepByName('SOAP Request').setAuthProfile('Profile Name')
    

    Any test step that implements the AuthProfileHolderContainer interface should be able to use the above script.

     

  • Radford's avatar
    Radford
    Super Contributor

    I have very rarely had to dynamically change the auth profile. This can be achived by the following Groovy Script:

     

    testRunner.getTestCase().getTestStepByName('SOAP Request').setAuthProfile('Profile Name')
    

    Any test step that implements the AuthProfileHolderContainer interface should be able to use the above script.

     

    • bpistole's avatar
      bpistole
      Contributor

      Here's what I ultamitely used to get this working.

       

      def step = testRunner.testCase.getTestStepByName("TestStepName").getHttpRequest();
      step.setSelectedAuthProfile(authProfile);

  • Lucian's avatar
    Lucian
    Community Hero

    Hey,

     

    Well if you have 3 environments (eg. env1, env2, env3) you can then create 3 auth profiles (eg. auth_env1, auth_env2, auth_env3). 

     

    In your ReadyApi application you can then select env1 and assign all requests that need authentication the auth_env1 profile, then switch to env2 and do the same and so on. 

     

    This is how I currently work with it.