Page tree
Skip to end of metadata
Go to start of metadata

When creating a GridClient, you can use an access key for authentication. The access key represents a combination of username, project name, and password.

Access keys have a limited lifespan, and once a key's expiry date has passed, it can no longer be used for authentication.

Your key is tied to your project and your login password.  If you are using multiple projects, each will need to have its own key. If you change your password, your keys will become invalid and you'll need to re-generate them.

Whenever a user is created or a user had changed his password, an access key is generated. 

View the Access Key

  • In the Cloud UI, click on user's profile and then click "Get Access Key".



  • Access key dialog will open.

  • Enter your login password to view your Access key


  • Your new key is now visible in the text box:



  • Make a note of your key text, and click "Close".

To invalidate your keys, simply change your password.


You can now use your key to authenticate a GridClient:

GridClient
Gridclient grid = new GridClient(<accessKey>(string), <CloudServerAddress>(string), <cloudServerPort>(int), <isCloudServerSecured>(boolean));
grid.lockDeviceForExecution(<testName>(string), <device Xpath query>(string), <reservation time in minuets>(int), <Timeout waiting for device in miliseconds(long));


You can now use your key to authenticate Appium:

Appium Capabilities
// specify access key via desired capabilities 
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("accessKey", accessKey);
AndroidDriver driver = new AndroidDriver<>(new URL("http://"+cloudHostAndPort+"/wd/hub"), dc); 
Appium
// specify access key via URL user info part 
AndroidDriver driver = new AndroidDriver<>(new URL("http://any:"+accessKey+"@"+host+":"+port+"/wd/hub"), dc); 




You can now use your key to authenticate API V1 calls:

API v1
package manageUsers;

import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.Base64;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
public class users {
    private static final String USERS_URL = "/users";
    private String host = "ServerIP";//TODO: IP goes here
    private String port = "port";//TODO: open port goes here
    private String webPage= "http://" + host + ":" + port + "/api/v1";
    private String AccessKey;

    @Before
    public void setup() {
      
        AccessKey = "AccessKeyLongString";//TODO: Admin Access Key is here
       
    }

    @Test
    public void testGetUsers() throws IOException {

     doGet(USERS_URL, webPage, accessKey);
    
    }

    protected void printGet(URL url, HttpURLConnection httpURLConnection, String result) throws IOException {
        int responseCode = httpURLConnection.getResponseCode();
        System.out.println("\nSending 'GET' request to URL : " + url);
        System.out.println("Response Code : " + responseCode);
        System.out.println(result);
    }

    /**
     * @param entity can be "/users" / "/projects" / "/devices" etc
     */
    protected String doGet(String entity, String webPage, String authStringEnc) throws IOException {
        URL url = new URL(webPage+entity);
        URLConnection urlConnection = url.openConnection();
        urlConnection.setRequestProperty("authorization", "Bearer " + authStringEnc);
        InputStream is = urlConnection.getInputStream();
        InputStreamReader isr = new InputStreamReader(is);
        int numCharsRead;
        char[] charArray = new char[1024];
        StringBuffer sb = new StringBuffer();
        while ((numCharsRead = isr.read(charArray)) > 0) {
            sb.append(charArray, 0, numCharsRead);
        }
        String result = sb.toString();
        boolean isResponseValid = ((HttpURLConnection)urlConnection).getResponseCode() < 300;
        Assert.assertTrue("Did not get a valid response", isResponseValid);
        return result;
    }
}



  • No labels