当前位置:网站首页>【208】基于AccessToken方式实现API设计
【208】基于AccessToken方式实现API设计
2022-06-28 16:06:00 【米洛口】
一、举例说明:
需求:
A、B机构需要调用X服务器的接口,那么X服务器就需要提供开放的外网访问接口。
分析:
1、开放平台提供者X,为每一个合作机构提供对应的appid、app_secret。
2、appid是唯一的(不能改变),表示对应的第三方合作机构,用来区分不同机构的。
3、app_secret在传输中实现加密功能(秘钥),该秘钥可以发生改变的。
4、为什么app_secret是可以改变的?调用接口需要appid+app_secret生成对应的access_token(临时性),如果appid和app_secret被泄密,产生安全性问题,如果一但发现被泄密,可以重新生成一个app_secret。
原理:为每个合作机构创建对应的appid、app_secret,生成对应的access_token(有效期2小时),在调用外网开放接口的时候,必须传递有效的access_token。
二、开发步骤
1、使用appid+app_secret生成对应的access_token
1.获取生成的AppId和appSecret,并验证是否可用
2.删除之前的accessToken
2.AppId和appSecret保证生成对应唯一的accessToken
注意:以上第二步必须保证在同一事务中
3.返回最新的accessToken
2、使用accessToken调用第三方接口
1.获取对应的accessToken
2.使用AccessToken查询redis对应的value(appId)
3.如果没有获取到对应的appid,直接返回错误提示
4.如果能获取到对应的appid,使用appid查询对应的APP信息
5.使用appId查询数据库app信息,获取is_flag状态,如果为1,则不能调用接口,否则正常执行
6.直接调用接口业务
边栏推荐
- 【Hot100】2. Add two numbers
- 一次简单的反射型XSS操作及思路
- 首次失败后,爱美客第二次冲刺港交所上市,财务负责人变动频繁
- IPDK — Overview
- A little hesitant in the morning
- Kiss in the metauniverse! CMU launched VR head display plug-in, reproducing the vivid touch of lips
- Etcd visualization tool: an introduction to kstone (I)
- 运动App如何实现端侧后台保活,让运动记录更完整?
- Summer Challenge ohos build custom service practice
- 浅谈 SAP 软件里的价格折扣设计原理
猜你喜欢

Cross cluster deployment of helm applications using karmada

Tiktok actual battle ~ list of bloggers I follow, follow and check

运维-- 统一网关非常必要

北京有哪些牛逼的中小型公司?

3. Caller 服务调用 - dapr

Etcd visualization tool: an introduction to kstone (I)

On the design principle of price discount in SAP software

The first place on the list - brake by wire "new cycle", the market competitiveness of local suppliers is TOP10
![[high concurrency foundation] hidden dangers and solutions of MySQL concurrency under different transaction isolation levels](/img/35/63c9793ec7bc1c90c759504e84dc96.png)
[high concurrency foundation] hidden dangers and solutions of MySQL concurrency under different transaction isolation levels

平台即代码的未来是Kubernetes扩展
随机推荐
Ffmpeg forbidden output banner log (30)
REDIS00_ Explain redis Conf configuration file
[recommendation system] esmm model of multi task learning (updating)
Focus on the 35 year old Kan: fear is because you don't have the ability to match your age
机器学习之卷积神经网络Lenet5训练模型
零钱兑换(动态规划)
A little hesitant in the morning
China energy integration and Tianyi cloud create an "energy brain"
【Hot100】2. Add two numbers
5分钟的时间制作一个反弹球游戏
首次失败后,爱美客第二次冲刺港交所上市,财务负责人变动频繁
【Hot100】3. Longest substring without duplicate characters
[high concurrency foundation] hidden dangers and solutions of MySQL concurrency under different transaction isolation levels
Azure Kinect Microsoft camera unity development summary
Yesterday, metauniverse | Wal Mart set up an innovation department to explore metauniverse and Web3, and Dior released the metauniverse Exhibition
中能融合携手天翼云打造“能源大脑”
wallys/DR7915-wifi6-MT7915-MT7975-2T2R-support-OpenWRT-802.11AX-supporting-MiniPCIe-Module
【Proteus仿真】L297驱动步进电机
Technical secrets of ByteDance data platform: implementation and optimization of complex query based on Clickhouse
Cross cluster deployment of helm applications using karmada