安全内核ed Feature Service Authentication -Example

1253
8
06-16-2021 06:58 PM
AnnCrystal
New Contributor II

I am wondering whether any of you have a sample of creating a login for a Secured Feature Service in a Federated Server authenticated through portal? The examples provided are authenticating thru' arcgis.com and not giving an option for ArcGIS Enterprise. I a newbie- please ignore my starting trouble.

Thanks

0Kudos
8 Replies
John_Spence
Occasional Contributor III

Are you just trying to lift the data through the API or are you trying to make it so a user does not have to log into a secured service when using a map product?

0Kudos
AnnCrystal
New Contributor II

What I am trying to accomplish is - edit a secured Feature table published as a featureservice in a federated server. Normally when you load a secured featureservice, it will prompt for user credentials.

So, what I am trying to do is authenticate it first and then pass the credentials to that feature service (remember the session) and perform add/edit/update etc on that feature table.

The Oauth2 example shows how to authenticate through ArcGIS.com which doesn't give an option to switch the login to ArcGIS enterprise. If you have an example to accomplish this- that would be great. I though this is a common scenario which everybody come across to do a basic CRUD operation against a feature layer/table. But, stuck on where to start:disappointed_face:without a sample.
Also, please suggest some learning recommendations too. Thanks!

0Kudos
John_Spence
Occasional Contributor III

I am assuming you are doing this outside of Pro, Desktop or a Web Application Builder type app and directly inserting via API.

Python示例:

def get_token():
#-------------------------------------------------------------------------------
# Name: Function -
# Purpose:
#-------------------------------------------------------------------------------

data = checklist.b64decode(AGOL_Pass)
pw = data.decode("ascii")

url = 'https://www.arcgis.com/sharing/rest/generateToken'
values = {'f': 'json',
'username': AGOL_User,
'password': pw,
'referer' : 'https://www.arcgis.com',
'expiration' : '10'}

data = urllib.parse.urlencode(values).encode("utf-8")
req = urllib.request.Request(url)

response = None
while response is None:
try:
响应= urllib.request.urlopen(要求、数据=数据)
except:
pass

the_page = response.read()

#Garbage Collection with some house building
payload_json = the_page.decode('utf8')
payload_json = json.loads(payload_json)

edit_token = payload_json['token']

return (edit_token)

If you are trying to do this through a web app as an example though, you can take the route of getting a long term token. In this case though, there are some perils involved depending on how you configure things. You would tack on ?token={}, {} being the token you would insert for the service. This would allow you to use a Portal account as authentication for that feature service.

0Kudos
John_Spence
Occasional Contributor III

Oh!!! The URL for the portal token you may need is here:https://yourserver.com/webadaptorname/admin/login

I am assuming you are going to use the Portal server in that URL and portal web adaptor name.

0Kudos
John_Spence
Occasional Contributor III
0Kudos
AnnCrystal
New Contributor II

Thank you very much! Yes, I looked into Oauth jsapi one- confused with how to get it to work in Enterprise. I am sorry, I should have mentioned how I was trying to achieve it. I am trying to put together a basic web app- through javascript. The python example is great- by any chance- do you have a javascript example?

0Kudos
John_Spence
Occasional Contributor III
0Kudos
AnnCrystal
New Contributor II

Awesome- I could sign into portal. How can I pass that credential to a secured map service layer?

0Kudos