获取asp.net Web表单中的访问令牌 [英] Get the access token in asp.net web forms
问题描述
我想获取访问令牌以调用Web表单应用程序中的一些api,但是我想说该应用程序已经是一个大项目,并且我不想使用任何库,我只想单击一个按钮,输入名称/密码,并获取访问令牌,我只想在页面代码中进行操作,而不会影响整个项目,例如安装库.
I want to get the access token to call some apis in my web form application , but I want to say that application already is a big project , and I don't want to use any library, I only want to click a button, enter name/password, and get access token , all I want to do is inside a page code , not anything other may affect the whole project , such as install a library .
推荐答案
我之前已经在Web窗体应用程序中完成了相关的代码示例,但是您首先应该了解此处以获取代码示例.您会在我的代码中发现我使用ADAL使用授权代码来获取访问令牌.您需要做的是通过以下方式修改AcquireTokenWithResource
函数:
I've done related code sample before in a web forms application , but you should firstly understand how authorization code flow works in AAD . After that , you could click here for code sample . And you will find in my code i use ADAL to get the access token using the authorization code . What you need to do is that modify the AcquireTokenWithResource
function by :
- 准备请求参数,并将POST请求发送到/token端点.
- 反序列化json结果并获取访问令牌.您可以使用Newtonsoft.Json库.
在编码过程中遇到任何问题,请随时告诉我.
Any problem during coding , please feel free to let me know .
这篇关于获取asp.net Web表单中的访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!