简体   繁体   English

如何使用WSO2 API Manager 1.10.0刷新应用程序的访问令牌?

[英]How to refresh the access token of an Application with the WSO2 API Manager 1.10.0?

I've (finally) managed to get a valid access token for an application using the API with the WSO2 API Manager 1.10.0. 我(最终)设法使用带有WSO2 API Manager 1.10.0的API获取应用程序的有效访问令牌。 However, it is unclear to me how to refresh this token. 但是,我不清楚如何刷新此令牌。

I got the working access token by calling https://myapi.mydomain.com/api/am/store/v0.9/applications/generate-keys?applicationId=2b205ee5-5891-4913-96e0-b4952d7d2a4c with the following payload 我通过以下有效负载调用https://myapi.mydomain.com/api/am/store/v0.9/applications/generate-keys?applicationId=2b205ee5-5891-4913-96e0-b4952d7d2a4c获得了工作访问令牌

var payload = {
    'grant_type': 'password',
    'username': username, 
    'password': password,
    "validityTime": validityTime,
    "keyType": "PRODUCTION",
    "accessAllowDomains": [ domain ]
}

The result looks like this: 结果如下:

Generating application keys for application with id '2b205ee5-5891-4913-96e0-b4952d7d2a4c'
{ consumerKey: '5k7UDuFTV0UE7mESHerEIm2Nj3ga',
  consumerSecret: 'm1hS_SNfHF25l9lP9YjYpf977VUa',
  keyState: 'APPROVED',
  keyType: 'PRODUCTION',
  supportedGrantTypes:
   [ 'urn:ietf:params:oauth:grant-type:saml2-bearer',
     'iwa:ntlm',
     'refresh_token',
     'client_credentials',
     'password' ],
  token:
   { tokenScopes: [ 'am_application_scope', 'default' ],
     validityTime: 2678400,
     accessToken: 'be8661550ee51b7682902e58a58108f6' } }

So it does seem like I have the grant to refresh my access token. 所以看起来我有资金刷新我的访问令牌。 Howver the documentation only mentions how to do this when you have a refresh token, which is missing from the reply. 如果您有一个刷新令牌,文档只会提到如何执行此操作,而回复中缺少该令牌。 What am I doing wrong? 我究竟做错了什么?

The API you used to generate tokens is not the API for your job. 您用于生成令牌的API不是您工作的API。 The API 'applications/generate-keys' is there to generate application related keys (Client secret and client id) . API'applications / generate-keys'用于生成与应用程序相关的密钥(客户机密钥和客户机ID)。 The token generated for this has a client_credential grant type. 为此生成的令牌具有client_credential授权类型。 thats why you do not get a refresh token. 这就是为什么你没有获得刷新令牌。 That token is generated using the client id and secret. 该令牌是使用客户端ID和密码生成的。

I see you have sent the grant type as 'password' in the payload but those parameters are not valid to start with. 我发现您已在有效负载中将授权类型作为“密码”发送,但这些参数无效。 that api does not accept grant type name. api不接受授权类型名称。 (api is there to generate the application keys. so grant type is not needed) (api用于生成应用程序密钥。因此不需要授予类型)

Actual sample payload (see https://docs.wso2.com/display/AM1100/apidocs/store/#!/operations#ApplicationindividualApi#applicationsGenerateKeysPost ) 实际样本有效负载(请参阅https://docs.wso2.com/display/AM1100/apidocs/store/#!/operations#ApplicationindividualApi#applicationsGenerateKeysPost

{ 
  "validityTime": "3600",
  "keyType": "PRODUCTION",
  "accessAllowDomains": ["ALL"
  ]
}

to generate the tokens please use the token api ( https://docs.wso2.com/display/AM1100/Token+API ). 要生成令牌,请使用令牌api( https://docs.wso2.com/display/AM1100/Token+API )。 Those apis are implemented according to the OAuth2 specs. 那些apis是根据OAuth2规范实现的。 You will get a refresh token when you use 'password' grant type using these token apis 使用这些令牌apis使用“密码”授权类型时,您将获得刷新令牌

You can refresh the token in API Store (developer portal), if you click on the Subscriptions tab, and there either: 如果单击“ 订阅”选项卡,则可以在API Store(开发人员门户)中刷新令牌,并且:

  • Manually click the Re-generate button refresh right now, or 立即手动单击“ 重新生成”按钮刷新,或者
  • Click the cURL button to generate the command that you can use to refresh programmatically: 单击cURL按钮以生成可用于以编程方式刷新的命令:

使用“订阅”选项卡上的cURL按钮生成令牌刷新调用

Notes: 笔记:

暂无
暂无

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

相关问题 在WSO2 API Manager 1.10.0的分布式部署中生成OAuth密钥 - Generating OAuth Key in distributed deployment of WSO2 API Manager 1.10.0 从WSO2 Api Manager检索用户访问令牌 - Retrieve user access TOKEN from WSO2 Api Manager WSO2 api管理器-如何显示“按应用程序使用API​​”的报告 - WSO2 api manager - How to display report on “API Usage by Application” 要使用来自WSO2 ESB的令牌访问已发布的WSO2 API管理器API,无法从WSO2 API管理器获取访问令牌 - To access Published WSO2 API Manager APIs using tokens from WSO2 ESB, Unable to get the access token from WSO2 API Manager 无法访问统计信息 - WSO2 API Manager和WSO2 BAM - Cannot access statistics - WSO2 API Manager and WSO2 BAM WSO2 API Manager管理员服务:如何创建应用程序 - WSO2 API Manager Admin Service : how to create application WSO2 API管理器-是否可以在没有访问令牌/订阅的情况下访问API? - WSO2 API Manager- Can we access API without access token / subscription? WSO2 API管理器-连接WSO2 API管理器以执行令牌API操作(如生成生产密钥,令牌,刷新令牌等)的Java代码示例 - WSO2 API Manager - java code sample to connect WSO2 API manager to do TOKEN API operations like generate production keys, tokens, refresh tokens etc 适用于多个用户的WSO2 Api Manager应用程序 - WSO2 Api Manager Application for several users WSO2 Api Manager:如何记录服务 - WSO2 Api Manager: How to log the services
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM