Hello there,
I tried following the steps here: https://developers.arcgis.com/unity/authentication/ (Components and C# API) but didn't manage to show the login page on Windows and Android.
Anyone managed to make it work?
These are my steps:
1. Made an empty scene.
2. Added OAuthScene script to an empty gameObject and added the client ID, Redirect URI mobile(unitydl://mylink?scene1), desktop(random website) and service URL which is a link to a 3D layer.
3. Added also OAuthChallengeHandlersInitializer script to the same gameObject.
Also tried to add the same components to an ArcGIS Map gameObject but the login page never shows.
Thanks.
Solved! Go to Solution.
Good news,
I tried to use the Authorization endpoints (https://www.arcgis.com/sharing/rest/oauth2/authorize?client_id=<APP_CLIENT_ID>&response_type=code&expiration=<N_SECONDS>&redirect_uri=<REDIRECT_URI>)
and it worked with all redirect links(HTTPS and unity deeplinks)! I think it's a bug in the SDK when reading the URI.
So here are the steps if anyone has the same issue:
1. Setup your application info. here: Applications Auth. and add unity's deep link for android example: unitydl://mylink?scene1
2. Enable deep link in unity (Enabling deep linking).
2. Open the URL using a script ("https://www.arcgis.com/sharing/rest/oauth2/authorize?client_id= <APP_CLIENT_ID>&response_type=code&expiration=<N_SECONDS>&redirect_uri=<REDIRECT_URI>") (don't forget to add your info. and remove the < >, more info. here: Mobile Endpoints ).
3. If everything is correct, your default browser will open asking you to log in.
4. After logging in the REDIRECT_URI which is a deep link will make you return to the app.
5. You can split the deep link and extract the auth. code which will be used to get the access token.
6. Use unity's web request with this URL to get the access token ("https://www.arcgis.com/sharing/rest/oauth2/token?client_id=<CLIENT_ID>&redirect_uri=<REDIRECT_URI>&grant_type=authorization_code&code=<CODE>")
7. The response will look like this: { "access_token":"{token}", "expires_in":1800, "username":"{user-name}", "refresh_token":"{refresh-token}" }.
Regards.
Open one of our component examples and don't add the OauthScene script (that is for api worfklows)
At the bottom of the ArcGIS Map Component setup the oauth configuration entirely thru the inspector and let me know if you get it to work.
I opened the ComponentGlobalSample scene and configured the OAuth then added a private layer and chose the auth. for all layers:
Now it gives me an error related to the URI:
and here are my app. settings in the dev. dashboard:
Ok we shouldn't be erroring like that for the api key in this case but if you add an api key does it work?
Adding an API key will always load the layers and ignore the auth.
I also just realized that your redirect URL probably doesn't make sense. On windows the localhost is typically used for the redicect since the local user needs to authenticate. It doesn't make sense to ask a remote server open the auth workflow.
You are correct! I added http://localhost:1234/auth as you mentioned here: Automatic authentication in the background and now I can see the auth. page in the browser.
What about android? I tried using unity's deep link: unitydl://mylink?scene1 but it keeps saying URI is invalid.
Good news,
I tried to use the Authorization endpoints (https://www.arcgis.com/sharing/rest/oauth2/authorize?client_id=<APP_CLIENT_ID>&response_type=code&expiration=<N_SECONDS>&redirect_uri=<REDIRECT_URI>)
and it worked with all redirect links(HTTPS and unity deeplinks)! I think it's a bug in the SDK when reading the URI.
So here are the steps if anyone has the same issue:
1. Setup your application info. here: Applications Auth. and add unity's deep link for android example: unitydl://mylink?scene1
2. Enable deep link in unity (Enabling deep linking).
2. Open the URL using a script ("https://www.arcgis.com/sharing/rest/oauth2/authorize?client_id= <APP_CLIENT_ID>&response_type=code&expiration=<N_SECONDS>&redirect_uri=<REDIRECT_URI>") (don't forget to add your info. and remove the < >, more info. here: Mobile Endpoints ).
3. If everything is correct, your default browser will open asking you to log in.
4. After logging in the REDIRECT_URI which is a deep link will make you return to the app.
5. You can split the deep link and extract the auth. code which will be used to get the access token.
6. Use unity's web request with this URL to get the access token ("https://www.arcgis.com/sharing/rest/oauth2/token?client_id=<CLIENT_ID>&redirect_uri=<REDIRECT_URI>&grant_type=authorization_code&code=<CODE>")
7. The response will look like this: { "access_token":"{token}", "expires_in":1800, "username":"{user-name}", "refresh_token":"{refresh-token}" }.
Regards.