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

推荐订阅源

C
Check Point Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 聂微东
月光博客
月光博客
博客园 - 司徒正美
爱范儿
爱范儿
aimingoo的专栏
aimingoo的专栏
量子位
Recent Announcements
Recent Announcements
V
V2EX
P
Proofpoint News Feed
小众软件
小众软件
云风的 BLOG
云风的 BLOG
腾讯CDC
宝玉的分享
宝玉的分享
Microsoft Azure Blog
Microsoft Azure Blog
大猫的无限游戏
大猫的无限游戏
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
A
About on SuperTechFans
B
Blog
博客园_首页
GbyAI
GbyAI
博客园 - Franky

博客园 - 咒语

跨线程 操作Winform 主UI时的扩展方法 每当双11来时,商家与京东的那些骚操作,京东30天保价不能信 Microsoft.Extensions.DependencyInjection 阅读笔记 EasyToLearnDesignPattern C#中关于表达式与委托在EF中的不同表现总结 软件开发中的版本号 The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported. ABP项目依赖图,根据自已生在的Demo项目分析而得 学习ELk之----02. Elastic Search操作入门 学习ELK之----01.建立ELK测试项目 一目了然呀的VS2017 Live Test 在Hyper-V上安装RemixOS 的Android模拟器 配置Asp.Net Web项目NLog配置文件的位置 配置WinRM的Https 测试EntityFramework,Z.EntityFramework.Extensions,原生语句在不同的查询中的表现。原来池化与非池化设定是有巨大的影响的。 消费RabbitMQ时的注意事项,如何禁止大量的消息涌到Consumer RabbitMQ调试与测试工具-v1.0.1 -提供下载测试与使用 安装TFS2015后启用生成功能 log4net在Realse下有个好大的坑呀。
Azure OAuth2 PostMan 授权代码
咒语 · 2022-01-07 · via 博客园 - 咒语

2022-01-07 10:46  咒语  阅读(237)  评论()    收藏  举报

//config varibales
const tokenLifeTime = 59;//minute
pm.environment.set('tenantDomain', 'dev.onmicrosoft.com') // Directories + subscriptions
pm.environment.set('client_credentials', 'client_credentials') // type
pm.environment.set('clientId', 'de1d0d77-') //
pm.environment.set('clientSecret', 'fUA=') //
pm.environment.set('resource', 'http://dev.com/cloudservices/system/test1/agent') //ResourcesId

//check bearerToken.
var oldToken = pm.environment.get('bearerToken');
var bearerTime = pm.environment.get('bearerTime');//last update bearerToken time 
var noToken = oldToken == undefined || oldToken == null || oldToken.trim() == '';
var expired = bearerTime == undefined || (new Date(bearerTime).addMinutes(tokenLifeTime) - new Date()) < 0;
if (noToken || expired) {
    console.log('BearerToken has expired.')
    pm.sendRequest(
        {
            url: 'https://login.microsoftonline.com/' + pm.environment.get('tenantDomain') + '/oauth2/token',
            method: 'POST',
            header: 'Content-Type: application/x-www-form-urlencoded',
            body: {
                mode: 'urlencoded',
                urlencoded: [
                    { key: 'grant_type', value: 'client_credentials', disabled: false },
                    { key: 'client_id', value: pm.environment.get('clientId'), disabled: false, },
                    { key: 'client_secret', value: pm.environment.get('clientSecret'), disabled: false, },
                    //{ key: 'scope', value: pm.environment.get('scope'), disabled: false },
                    { key: 'resource', value: pm.environment.get('resource'), disabled: false },
                ],
            },
        },
        function (err, res) {
            //pm.globals.set('bearerToken', res.json().access_token)
            pm.environment.set('bearerToken', res.json().access_token)
            pm.environment.set('bearerTime', new Date())
            console.log(pm.environment.get('bearerToken'))
        },
    )
} else {
    console.log('BearerToken is exist and life is ok.')
}

将上述代码置于左建点击某一Collection的Pre-request Script 后,再选中AuthorizationTab页修改为: