Forum Discussion

AAB's avatar
Regular Contributor
5 years ago

ReadyAPI: Using automated Authorization from Auth Repository

Hi all (  TanyaYatskovska  Nastya_Khovrina   nmrao   ....)   I've tried to use Auhtorization OAuth 2.0 to set it in Auth Repository level to be able to use this in a different projects but the au...
  • New2API's avatar
    5 years ago

    AAB, I believe the script you are looking is under "Calling the Automated Retreival Procedure".


    // Import the required classes

    // Set up variables
    def project = ModelSupport.getModelItemProject(context.getModelItem());
    def authProfile = project.getAuthRepository().getEntry("OAuth 2");
    def oldToken = authProfile.getAccessToken();
    def tokenType = TokenType.ACCESS;

    // Create a facade object
    def oAuthFacade = new OltuOAuth2ClientFacade(tokenType);

    // Request an access token in headless mode
    oAuthFacade.requestAccessToken(authProfile, true, true);

    // Wait until the access token gets updated
    while(oldToken == authProfile.getAccessToken()) {
    //The sleep method can be used instead of a while loop

    // Post the info to the log"Set new token: " + authProfile.getAccessToken());