惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 鞠强

HBase初探 HDInsight - 1,简介 Windows8.1画热度图 - 坑 使用windbg查看DependencyObject的属性 LiveSDK初始化/登录时失败的解决办法 开发WP版本的大菠萝英雄榜 SQL 2014 in-memory中的storage部分 XAML绑定 Kinect 1 Diablo3狗熊榜 微软上海招聘有经验的.NET开发人员 塔防蜀的存档分析 我的HD2手机 和我一起作Tess的windbg lab,结束 和我一起作Tess的windbg lab - Lab7, MemoryLeak 和我一起作Tess的windbg lab - Lab6, MemoryLeak - 鞠强 和我一起作Tess的windbg lab - Lab5, Crash 和我一起作Tess的windbg lab - Lab4, High CPU 和我一起作Tess的windbg lab - Lab3, Memory
C#访问Azure的资源
鞠强 · 2015-08-18 · via 博客园 - 鞠强

官方参考资料在这里:https://msdn.microsoft.com/en-us/library/azure/dn722415.aspx,本文放一些重点及遇到的坑的解决办法。

身份验证

不是说,我们把subscriptionID和本地的cert匹配一下就OK了,还需要在portal中配置,允许我们的APP访问这个portal。主要参考这里:Add an application to Azure AD。要注意的是,上文是4月15日的版本,但是现在(8月18日)的版本,已经不是在Set up directory这个TAB页上,而是在Develop Applications这个TAB上。 

在OAuth的回调页面中,不是两个URL,而是变成了一个,这里我写了http://localhost/。七月的,配置permission的时候,照做即可,别忘记点下面的保存。

添加引用

在VS工程里面,按照上面指南,management libraries是没问题的。但是注意第二个,AD auth的,搜索之后找到的,不是原文中的Active Directory Authentication Library,而是Microsoft.IdentityModel.Clients.ActiveDirectory(我擦,整天改名字,好玩吗?!)

修改配置

按照指南,把那一坨appSettings内容添加到app.config文件中,然后把OAUTH2对应的endpoint的GUID替换到app.config中的id-of-tenent。在另一个portal界面中,把id-of-client的值也替换到app.config文件中。

截止到step7为止,替换redirectUri遗迹subScriptionId。step8及之后,暂时不修改。

Token

按照指南做即可。此时就可以做验证了,在你的入口方法中调用GetAuthorizationHeader,如果能弹出来微软的ADFS认证窗口,并且你输入你自己的azure的管理员账号与密码,验证成功后,那么就没问题了。

这时,可以初步验证我们的代码了:

        private void button1_Click(object sender, EventArgs e)
        {
            var token = GetAuthorizationHeader();
            var credential = new TokenCloudCredentials(ConfigurationManager.AppSettings["subscriptionId"], token);

            var computeClient = new Microsoft.WindowsAzure.Management.Compute.ComputeManagementClient(credential);
            var services = computeClient.HostedServices.List().HostedServices;
        }

View Code