、認證方式有三種
Oauth2.0,
Token-based
http/windows
二、用戶登錄與應用登錄區別
兩者區別在於:當用戶登錄時,服務器端平台是否直接識別登錄信息和驗證登錄信息。
應用登錄是間接認證,可以在應用登錄的方法中增加額外的認證邏輯,如clientId、Ip等等。應用登錄是服務器端驗證,避免前端認證信息被盜用。
三、注冊應用程序
注冊程序后會出現
四、oauth2.0
(1)oauth2.0+user登錄 ,只需要注冊應用中的appid。 IdentityManager來管理認證信息。
例子參見anjiangis/portal_oauth_popup.html
var info = new ArcGISOAuthInfo({
appId: "<this is where your app id would go>",
popup: true
});
esriId.registerOAuthInfos([info]);
(2)oauth2.0+app 需要AppID 和AppSecret
利用注冊應用中的登錄,注冊應用可以自主添加登錄認證方法(如ip)。
參考
https://developers.arcgis.com/javascript/3/jshelp/tutorial_sharing_maps_secure_layers.html
代碼等在anjiangis文件夾下的traffic和resource-proxy-master。
這個例子是結合資源代理,無需登錄。比較迷糊。
五、token
(1)token+user login
例子參見anjiangis/portal_oauth_popup.html
登錄獲取token,下次請求攜帶token的示例
https://servicesbeta.esri.com/security/index.html
(2)token+app login
注冊應用在服務器端管理token,與資源代理合用。
四、示例代碼
Oauth2.0+user login
https://developers.arcgis.com/javascript/3/jssamples/portal_oauth_inline.html
cookie保存憑證信息
https://developers.arcgis.com/javascript/3/jssamples/widget_identitymanager_client_side.html
代理方式
https://developers.arcgis.com/javascript/3/jshelp/tutorial_sharing_maps_secure_layers.html
proxy for dotnet 代碼下載及使用教程
https://github.com/Esri/resource-proxy/blob/master/DotNet/README.md
token獲取和利用方式
五、自身實踐
采用簡單的oauth2.0+app方式。 需要AppID 和AppSecret
(1)將需要保護的內容/服務改為公開為某個用戶或組織
(2)在gisonline或者portal上添加應用程序,並查看app的AppID 和AppSecret。此信息是用來給客戶端訪問,獲取token的,該token就可以訪問該用戶下的其他受保護內容/服務。
(3)用postman測試下,能否登錄成功,獲取token.
(4)請求服務時攜帶token即可
token = "Z-tB9aDlY9Lzp9bJOZiRMLhqnCis1……aorCzVs2PUg5gIz-3crqTwGmQ..";
var fUrl = "https://services8.arcgis.com……/arcgis/rest/services/enterprise/FeatureServer/0?token=" + token;
var featureLayer = new FeatureLayer({
url: fUrl
});
map.add(featureLayer);