ArcGIS Runtime.NET SDK100.0.0 使用 Named User 进行OAuth授权
分享
作者:徐鸿至 发布时间: 2017-2-9
Overview
关于OAuth的概念,建议阅读一下这篇文章
这个例子将一步步的解释ArcGIS Runtime.NET SDK100.0.0 进行 Named User OAuth授权的详细步骤.
Steps
授权代码
// Challenge the user for portal credentials (OAuth credential request for arcgis.com)
CredentialRequestInfo loginInfo = new CredentialRequestInfo();
// Use the OAuth implicit grant flow
loginInfo.GenerateTokenOptions = new GenerateTokenOptions
{
TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit
};
// Indicate the url (portal) to authenticate with (ArcGIS Online)
loginInfo.ServiceUri = new Uri("https://www.arcgis.com/sharing/rest");
// Call GetCredentialAsync on the AuthenticationManager to invoke the challenge handler
Credential cred = await AuthenticationManager.Current.GetCredentialAsync(loginInfo, false);
// Connect to the portal (ArcGIS Online) using the credential
ArcGISPortal arcgisPortal = await ArcGISPortal.CreateAsync(loginInfo.ServiceUri, cred);
// Get LicenseInfo from the portal
Esri.ArcGISRuntime.LicenseInfo licenseInfo = arcgisPortal.PortalInfo.LicenseInfo;
var licenseJson = licenseInfo.ToJson();
using (StreamWriter outputFile = new StreamWriter(@"lincese.json"))
{
// you can save the license file for latter offline use.
outputFile.WriteLine(licenseJson);
}
// ... code here to license the app immediately and/or save the license (JSON string) to take the app offline ...
// License the app using the license info
Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.SetLicense(licenseInfo);
系统需求
文章来源:
https://github.com/crazyxhz/License.NetAppByNamedUser/blob/master/README_CN.md
作者:徐鸿至 发布时间: 2017-2-9
Overview
关于OAuth的概念,建议阅读一下这篇文章
这个例子将一步步的解释ArcGIS Runtime.NET SDK100.0.0 进行 Named User OAuth授权的详细步骤.
Steps
- 注册ArcGIS Online两个月的试用. 点击打开链接,根据网站中的提示完成两个月试用的注册.
- 登录ArcGIS Online的主页,点击我的内容:
- 点击添加项目,点击添加程序
- 选择程序类型,选择标题和标签
- 程序创建之后,点击刚刚创建的程序,点击设置标签页
- 将页面滚动到底部,点击Registered Info查看Oauth2信息
- 将对应的信息填入你的代码中
- 编译Oauth项目,完成!
- 水印已经消除.
授权代码
// Challenge the user for portal credentials (OAuth credential request for arcgis.com)
CredentialRequestInfo loginInfo = new CredentialRequestInfo();
// Use the OAuth implicit grant flow
loginInfo.GenerateTokenOptions = new GenerateTokenOptions
{
TokenAuthenticationType = TokenAuthenticationType.OAuthImplicit
};
// Indicate the url (portal) to authenticate with (ArcGIS Online)
loginInfo.ServiceUri = new Uri("https://www.arcgis.com/sharing/rest");
// Call GetCredentialAsync on the AuthenticationManager to invoke the challenge handler
Credential cred = await AuthenticationManager.Current.GetCredentialAsync(loginInfo, false);
// Connect to the portal (ArcGIS Online) using the credential
ArcGISPortal arcgisPortal = await ArcGISPortal.CreateAsync(loginInfo.ServiceUri, cred);
// Get LicenseInfo from the portal
Esri.ArcGISRuntime.LicenseInfo licenseInfo = arcgisPortal.PortalInfo.LicenseInfo;
var licenseJson = licenseInfo.ToJson();
using (StreamWriter outputFile = new StreamWriter(@"lincese.json"))
{
// you can save the license file for latter offline use.
outputFile.WriteLine(licenseJson);
}
// ... code here to license the app immediately and/or save the license (JSON string) to take the app offline ...
// License the app using the license info
Esri.ArcGISRuntime.ArcGISRuntimeEnvironment.SetLicense(licenseInfo);
系统需求
- Visual Studio 2015
- ArcGIS Runtime.NET SDK100.0.0
文章来源:
https://github.com/crazyxhz/License.NetAppByNamedUser/blob/master/README_CN.md
0 个评论
推荐内容
- ArcGIS Runtime SDK for Android 100.3.0加载离线.slpk文件
- ArcGIS Runtime SDK 100.0.0 Loadable设计模式剖析
- Linux上安装ArcGIS Enterprise超详细教程——以Redhat7.2上安装ArcGIS Enterprise 10.5为例
- ArcGIS Runtime 100 许可策略解读
- ArcGIS Desktop 10.x 授权Ⅰ——在线激活授权码
- ArcGIS系统要求知多少
- Linux上安装ArcGIS for Server超详细教程——以Redhat6.5上安装ArcGIS for Server 10.3.1为例
- ArcGIS Runtime是什么?包括什么产品?
相关问题
- 如何优雅的使用ArcGIS知乎?
- 建设ArcGIS知乎平台的目和意义?
- ArcGIS知乎社区改进意见征集
- 苹果系统下可以使用arcgis 吗?
- arcgis版本兼容性
- 请问ArcGIS适合在局域网内用javaweb做二次开发吗?
- 请问大神们,怎么用ArcGIS做城镇间经济联系强度的图?
- ArcGIS如何求栅格图像的“质心”
- 在Visual studio 2015 中使用 Arcgis API for JavaScript v3.16 如何实现代码智能提示?
- 请问arcmap如何使用多线程?
- 在windows server2008 R2 64位中安装了portal 10.5 设置好托管arcgis server站点,并用data store为托管数据库,发布数据出错