wso2 API-M 3.0 - 如何为产品/管理 API 调用获取 oauth 令牌 [英] wso2 API-M 3.0 - how to get oauth token for product/admin api calls

查看:65
本文介绍了wso2 API-M 3.0 - 如何为产品/管理 API 调用获取 oauth 令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用通用管理员/管理员凭据测试 wso2 API-M 的预发布版本 3.0,并希望调用 http://wso2.github.io/carbon-apimgt/apis/publisher/v1.0/ - 例如创建一个新的api.

所有这些 api 都采用 oauth 访问令牌,但是在他们的文档中,我只看到了它们的 oauth2 范围,但我没有看到如何生成访问令牌以传递 api 请求.
很清楚如何为已在 wso2 store/publisher 中创建的 api 和应用程序生成 oauth 令牌,但我一直无法在 https://docs.wso2.com/display/AM300/Product+APIs.

我知道较早版本的 wso2 具有带有管理和身份服务器 UI 的carbon"端点,这可能对此有所帮助,但是这个新版本没有该端点,而我偶然发现的admin"端点没有产生与 oauth 令牌相关的任何内容.任何想法如何获取 oauth 凭据来调用这些 api?谢谢.

解决方案

您需要执行以下操作.

  1. 使用 DCR 端点,创建一个 oauth 应用程序并生成客户端密钥和机密.

    curl -X POST -H "Content-Type: application/json" -H "Authorization: Basic YWRtaW46YWRtaW4=" --data @payload.json https://localhost:9443/api/identity/oauth2/dcr/v1.0/register -kv

payload.json 内容

<预><代码>{redirect_uris":[http://本地主机"],"client_name": "name_1",grant_types":[密码"]}

授权令牌是 Base64 编码的(用户名:密码)

  1. 使用密码授权类型获取访问令牌

    curl -X POST -H "授权: 基本 MTNiYmM1ODAtYjkwYy00ZDg0LWE5NjItYjg4NTg2Yzk1MmEyOjYxZGE1M2YwLTkxN2MtNDhmNi1hYWEzLWVmMDU3NjEzd"-admin&mdu3NjEzmdhref-user=admin& urlx-password = admin = admin = admin = admin&dM 应用程序"https://localhost:9443/api/auth/oauth2/v1.0/token?grant_type=password&scope=scope" rel="nofollow noreferrer">https://localhost:9443/api/auth/oauth2/v1.0/token?grant_type=password&scope=scope" -kv

授权令牌是 Base64 编码的(clientId:clientSecret)

  1. 使用收到的令牌调用 API

    curl -X GET -H "授权:承载 9uAXi-J5GywvdTupCjbg005-NdqDSfD397vI_UKcbaw" "https://localhost:9443/api/am/publisher/v1.0/apis/" -kv

更多详情请参考以下内容

  1. https://docs.wso2.com/display/AM300/DCR+and+DCRM+APIs
  2. https://docs.wso2.com/display/AM300/Token+API

I am testing out the pre-release version 3.0 of wso2 API-M with the generic admin/admin credentials and want to invoke the various publisher apis at http://wso2.github.io/carbon-apimgt/apis/publisher/v1.0/ - e.g. creating a new api.

All of these apis take oauth access tokens, however in their documentation I only see the oauth2 scope for them noted, but I don't see how to generate the access token to pass in the api request.
It is clear how to generate oauth tokens for apis and apps already created in wso2 store/publisher, but I have not been able to find how to generate the oauth token for the higher-level product apis at https://docs.wso2.com/display/AM300/Product+APIs.

I know earlier versions of wso2 had the "carbon" endpoint with the admin and identity server UI which maybe helped with this, but this new version doesn't have that endpoint and the "admin" endpoint I stumbled across doesn't yield anything related to oauth tokens. Any ideas how to get the oauth credentials to invoke these apis? Thanks.

解决方案

You need to do the following.

  1. Using DCR endpoint, create an oauth app and generate client key and secret.

    curl -X POST -H "Content-Type: application/json" -H "Authorization: Basic YWRtaW46YWRtaW4=" --data @payload.json https://localhost:9443/api/identity/oauth2/dcr/v1.0/register -kv

payload.json content

{
  "redirect_uris": [
    "http://localhost"
  ],
  "client_name": "name_1",
  "grant_types": [
    "password"
  ]
}

Authorization token is Base64 encoded(username:password)

  1. Get an access token using password grant type

    curl -X POST -H "Authorization: Basic MTNiYmM1ODAtYjkwYy00ZDg0LWE5NjItYjg4NTg2Yzk1MmEyOjYxZGE1M2YwLTkxN2MtNDhmNi1hYWEzLWVmMDU3NjEzMDdiMw==" -H "Content-Type: application/x-www-form-urlencoded" -d 'username=admin&password=admin' "https://localhost:9443/api/auth/oauth2/v1.0/token?grant_type=password&scope=scope" -kv

Authorization token is Base64 encoded(clientId:clientSecret)

  1. Invoke an API with the received token

    curl -X GET -H "Authorization: Bearer 9uAXi-J5GywvdTupCjbg005-NdqDSfD397vI_UKcbaw" "https://localhost:9443/api/am/publisher/v1.0/apis/" -kv

Refer the following for more details

  1. https://docs.wso2.com/display/AM300/DCR+and+DCRM+APIs
  2. https://docs.wso2.com/display/AM300/Token+API

这篇关于wso2 API-M 3.0 - 如何为产品/管理 API 调用获取 oauth 令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆