[英]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(开发人员门户)中刷新令牌,并且:
Notes: 笔记:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.