# Auth0 call to /oauth/token from android

**URL:** <https://community.auth0.com/t/auth0-call-to-oauth-token-from-android/15258>\
**Category:** Get Help\
**Tags:** api, auth0\
**Created:** [September 11, 2018, 11:50am UTC](https://community.auth0.com/t/auth0-call-to-oauth-token-from-android/15258 "2018-09-11T11:50:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexandra.damaschin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alexandra.damaschin/32/8301_2.png) [@alexandra.damaschin](https://community.auth0.com/u/alexandra.damaschin)\
**Post date:** [September 11, 2018, 11:50am UTC](https://community.auth0.com/t/auth0-call-to-oauth-token-from-android/15258/1 "2018-09-11T11:50:50Z")

</div>

Hello,

I am trying to make a call from an android app to auth0 /oauth/token to get my token.

I am sending all the parameters needed but I am still getting back a 401 and I am confused why.

That’s how I send the parameters:

urlConnection = (HttpURLConnection) url.openConnection();  
urlConnection.setRequestMethod(“POST”);  
urlConnection.setRequestProperty(“Content-Type”, “application/x-www-form-urlencoded”);  
//post parameters to url  
urlConnection.setDoInput(true);  
urlConnection.setDoOutput(true);  
urlConnection.setRequestProperty(“Charset”, “UTF-8”);

//to add parameters in the uri  
Uri.Builder builder = new Uri.Builder()  
 .authority(url.toString())  
 .appendQueryParameter(“grant\_type”, grant\_type)  
 .appendQueryParameter(“client\_id”, client\_id)  
 .appendQueryParameter(“audience”, audience)  
 .appendQueryParameter(“username”, email)  
 .appendQueryParameter(“password”, password)  
 .appendQueryParameter(“scope”, scope)  
 .appendQueryParameter(“client\_secret”, client\_secret);

builder.build().getEncodedQuery();  
urlConnection.setReadTimeout(10000 /\* milliseconds _/);  
urlConnection.setConnectTimeout(15000 /_ milliseconds \*/);  
urlConnection.connect();  
int responseCode = urlConnection.getResponseCode();

and my responseCode=401.

I am not sure if it’s a java code problem or a auth0 call problem.

---

<div class="post-metadata">

**Author:** ![kimcodes](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kimcodes/32/81052_2.png) [@kimcodes](https://community.auth0.com/u/kimcodes)\
**Post date:** [September 11, 2018, 1:12pm UTC](https://community.auth0.com/t/auth0-call-to-oauth-token-from-android/15258/3 "2018-09-11T13:12:16Z")

</div>

👋 Which grant type are you specifying as your parameter? I would suggest using the Authorization Code Grant (PKCE) if this is a native application ([which OAuth 2.0 flow to use](https://auth0.com/docs/api-auth/which-oauth-flow-to-use)). This OAuth 2.0 grant (for mobile apps) is used to access an API, so you use this endpoint to exchange an Authorization Code for a Token.

Authorization Code (PKCE):  
[https://auth0.com/docs/api/authentication#authorization-code-pkce-](https://auth0.com/docs/api/authentication#authorization-code-pkce-)

There is also documentation here on how to perform the exchange:  
[https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce](https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce)

---

<div class="post-metadata">

**Author:** ![alexandra.damaschin](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/alexandra.damaschin/32/8301_2.png) [@alexandra.damaschin](https://community.auth0.com/u/alexandra.damaschin)\
**Post date:** [September 11, 2018, 1:30pm UTC](https://community.auth0.com/t/auth0-call-to-oauth-token-from-android/15258/4 "2018-09-11T13:30:47Z")

</div>

Hello,

I am just trying to make a POST request to that url and get back the token. I have it working in postman but when I do implement it in android it just return me 401.

My grant\_type it’s set for password.

---

<div class="post-metadata">

**Author:** ![kimcodes](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/kimcodes/32/81052_2.png) [@kimcodes](https://community.auth0.com/u/kimcodes)\
**Post date:** [November 28, 2018, 6:16pm UTC](https://community.auth0.com/t/auth0-call-to-oauth-token-from-android/15258/5 "2018-11-28T18:16:59Z")

</div>

Have you set the `client_type` to Native? (we can do this in our dashboard under _Clients_ \> _Your Client Name_ \> _Settings_ for this) . Ive seen a 401 error thrown before when the `client_type` wasn’t properly set for an Android or iOS app. I will continue to investigate why we may be getting a 401 from `/oauth/token`

---

<div class="post-metadata">

**Author:** ![jerdog](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jerdog/32/11231_2.png) [@jerdog](https://community.auth0.com/u/jerdog)\
**Post date:** [January 22, 2019, 12:00am UTC](https://community.auth0.com/t/auth0-call-to-oauth-token-from-android/15258/6 "2019-01-22T00:00:01Z")

</div>

This topic was automatically closed after 14 days. New replies are no longer allowed.
