Puttzy
Puttzy

Reputation: 156

ADAL 4 Android not passing client secret

I'll first say that I'm sure it is just me since people have probably got this to work out of the box without having to edit the ADAL 4 Android Library without editing the source.

When running the sample program and authenticating with a token I get an error from AZURE that it is not passing the client_secret in the message body. I can confirm that this is in fact the case - it is not passing the client_secret.

Although if I edit the OAuth2.java file and change the method buildTokenRequestMessage to something like the following the workflow works perfectly

public String buildTokenRequestMessage(String code) throws UnsupportedEncodingException {
    String message = String.format("%s=%s&%s=%s&%s=%s&%s=%s&%s=%s",
            AuthenticationConstants.OAuth2.GRANT_TYPE,
            StringExtensions.URLFormEncode(AuthenticationConstants.OAuth2.AUTHORIZATION_CODE),

            AuthenticationConstants.OAuth2.CODE, StringExtensions.URLFormEncode(code),

            AuthenticationConstants.OAuth2.CLIENT_ID,
            StringExtensions.URLFormEncode(mRequest.getClientId()),

            AuthenticationConstants.OAuth2.REDIRECT_URI,
            StringExtensions.URLFormEncode(mRequest.getRedirectUri())

                  // these are the two lines I've added to make it work
             AuthenticationConstants.OAuth2.CLIENT_SECRET,
            StringExtensions.URLFormEncode("<MY CLIENT SECRET>")

            );
    return message;
}

Am I doing something wrong? If not, what is the correct way to access the client secret?

My implementation is straight from the demo application with only changes being setting up the strings to match my endpoints.

Thanks

Upvotes: 0

Views: 215

Answers (1)

Omer Cansizoglu
Omer Cansizoglu

Reputation: 1281

You need to register your app as a Native application at Azure AD portal. You don't need client secret for native app.

enter image description here

Upvotes: 1

Related Questions