0
votes

I am trying to connect to azure data lake using java program where i can get data to/from azure data lake, but my program is unable to authenticate and terminate with Bad Request error.

i have Microsoft free trail account and have done following steps.

  1. Registered web app on default azure active directory. (sign on URL is dummy)
  2. Copied auth-endpoint-token and application-id and generated client secret
  3. Already have permission (as i am the only user with default login)
  4. Added Azure data lake and given required permission.

Now i have this java code.

resource = "https://XXXXXlake.azuredatalakestore.net"
ClientCredsTokenProvider provider = new ClientCredsTokenProvider(authEndPointToken, clientID, clientSecret);
AzureADToken token = provider.getToken();

Now my question is,

  1. What is missing to cause Bad Request error ?
  2. BTW, i also do not see registered app under 'My apps' option, though it is visible when i select 'All apps' option ?

Thanks

2

2 Answers

0
votes

In my experience, this points to either a permissions' problem or wrong parameters being passed... although the error message doesn't say so.

Please check again your permissions. Make sure you have really given the Azure Active Directory App permission over the Data Lake Store top directory.

You might maybe give the App "Owner" rights over the adls just for testing purpose. You can also use the "Add User Wizard"

0
votes

Below Code is working for me. for this you need to provide clientid,clientkey,authTokenEndpoint and accountFQDN, which you can get from your azure data lake console. please make sure you given all necessary permission to your application to access azure active directory and location where you have your data.

public class TestConnection {

    public static void main(String[] args) {
        try {
            String clientId = "xyz";
            String authTokenEndpoint = "https://login.microsoftonline.com/6f04c329-75be-4f3f-bb37-ba8857b01aa6/oauth2/token";
            String clientKey = "abc";

            AccessTokenProvider provider = new ClientCredsTokenProvider(authTokenEndpoint, clientId, clientKey);
            String accountFQDN = "efg";  // full account FQDN, not just the account name
            ADLStoreClient client = ADLStoreClient.createClient(accountFQDN, provider);
            InputStream in = client.getReadStream("/abc/def/xyz.json");
            BufferedReader reader = new BufferedReader(new InputStreamReader(in));
            String line;
            while ( (line = reader.readLine()) != null) {
                System.out.println(line);
            }
            reader.close();
            System.out.println();
            System.out.println("File contents read.");
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 

    }
}