Select to view content in your preferred language

Android OAuth, what should I use for the redirect_uri?

2426
1
05-26-2020 05:45 AM
OrrinThomas
Emerging Contributor

I am struggling with OAuth in Android SDK.

I have created a new application, RobinAR, on ArcGIS for Developers .  That provided the Client ID needed for the 

OAuthConfiguration.  I didn't know what to do for the Redirect URL, so I followed the hint and made it, myapp://RobinAR.
Perhaps that should be RobinAR://<Something>?




0 Kudos
1 Reply
OrrinThomas
Emerging Contributor

I think I have this figured out:

The redirect_uri must be set, on the authorization tab of new application in developers.arcgis.com.  I found the clue that proved the key on how this done here ( https://developers.arcgis.com/labs/android/access-services-with-oauth-2/)
"Use this redirect URL when creating the OAuthConfiguration and the intent filter scheme when Android returns control back to your app after OAuth 2.0 login. If you change this value, you must change it in all three places.
If you already have an app defined, you can use that client ID instead of creating a new one." (you have to click the circle-i to open this)
  1. On developers.argis.com, in the Authetican tab of you application, add the redirect uri "<app_name>://auth"
  2. In the strings.xml create
    1. <string name="oauth_client_id"><Copied client ID></string>
    2. <string name="oauth_redirect_host">auth</string>
    3. <string name="oauth_redirect_uri">APP_NAME</string>
  3. In the java code:OAuthConfiguration oAuthConfiguration = new OAuthConfiguration(portalURL, getString(R.string.oauth_client_id), getString(R.string.oauth_redirect_uri) + "://" + getString(R.string.oauth_redirect_host));
  4. In the manifest.xml:
<!-- You must declare this activity, an intent receiver, to display the OAuth login -->
<activity
android:name="com.esri.arcgisruntime.security.DefaultOAuthIntentReceiver"
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="@string/oauth_redirect_host"
android:scheme=APP_NAME />  <!-- CHANGE APP NAME HERE!!!! -->
</intent-filter>
</activity>
0 Kudos