ArcGIS API 4.0 : Set token for access to Feature Layer from ArcGIS Online

2195
2
08-03-2016 04:49 AM
VasylynaMykhalchuk
New Contributor II

I want to create token for my feature layer from ArcGIS Online. Can anybody help me?

I know that I may use Identity Manager but never generate token before. Any ideas there are will be helpful!

0 Kudos
2 Replies
ReneRubalcava
Frequent Contributor

You can do one of two things to get tokens, which you usually don't need to worry about too many details.

Just add the IdentityManager and you'll get a dialog to log in.

IdentityManager | API Reference | ArcGIS API for JavaScript 4.0

This authentication is only for the current session, refresh the browser and you are asked to log in again.

The recommended method is to use OAuth.

You can look at this sample.

Access ArcGIS Online items using OAuthentication | ArcGIS API for JavaScript 4.0

Review the source code for this app by using "view source" or developer tools to check the source of this application.

The key here is to create an Application in ArcGIS Online, and get an appId/clientId.

Let me see if I can get the steps down for you here.

Click on "Add Item"

Go to the "Settings" tab for the item.

Click on "Update"

You'll see your "App ID" in there. I blurred it out, but it's really the client secret you do not want to share. If someone has your client secret, they can eat all your AGOL credits, so do not share it.

I also like to add "localhost" to the redirct URI. Then when you move this production, add the domain for the server your application will be running from.

Here is a link from that JSAPI sample to more docs on OAuth 2.0

ArcGIS Security and Authentication | ArcGIS for Developers

Hope that helps.

VasylynaMykhalchuk
New Contributor II

Thank you a lot! You even can't imagine how this advice helpful for me

0 Kudos