简体   繁体   English

如何在授权 header 中使用不记名令牌以安全方式调用 rest api? 请提供样品代码 c#

[英]how to call a rest api using a bearer token in authorization header in secure way? Sample code c# please

  1. How to store the JWT Bearer token I obtain into my APIM.如何将我获得的 JWT 不记名令牌存储到我的 APIM 中。 I obtain this token from an external provider outside of my network.我从我的网络之外的外部提供商处获得此令牌。 I pass some client credential, client id, secret etc我传递了一些客户凭证、客户 ID、秘密等

I am thinking to do in inbound policy, is that the right place?我想在入境政策中做,那是正确的地方吗? Also how to set the time for expiry of cache?另外如何设置缓存的到期时间? I am following this but it doesnt say where it has the time for expiry value but just variable I see.我正在关注这一点,但它没有说明它在哪里有到期价值的时间,而只是我看到的变量。 https://github.com/Azure/api-management-policy-snippets/blob/master/examples/Backend%20OAuth2%20Authentication%20With%20Cache.policy.xml https://github.com/Azure/api-management-policy-snippets/blob/master/examples/Backend%20OAuth2%20Authentication%20With%20Cache.policy.xml

  1. a sample C# Code for calling the third party api through the obtained token above how do I do in APIm or service fabric please?一个示例 C# 代码,用于通过上面获得的令牌调用第三方 api 我如何在 APIm 或服务结构中执行? I am new.我是新的。

How to store the JWT Bearer token I obtain into my APIM.如何将我获得的 JWT 不记名令牌存储到我的 APIM 中。

As you have provided, you can use <set-variable name="accessToken" value=""/> to store access token.正如您所提供的,您可以使用<set-variable name="accessToken" value=""/>来存储访问令牌。

how to set the time for expiry of cache如何设置缓存过期时间

The cache-store policy caches responses according to the specified cache settings. cache-store策略根据指定的缓存设置缓存响应。 Set response cache duration using maxAge value in Cache-Control header sent by the backend.使用后端发送的 Cache-Control header 中的 maxAge 值设置响应缓存持续时间。

<cache-store duration="seconds" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM