苏州网站搜索引擎优化,百度搜索引擎网站,建设微商城网站,手机管理wordpress站Jira配置应用程序链接
1) 创建应用程序链接
登录 JIRA 管理后台。转到 Administration Applications Application Links。在输入框中输入外部应用程序的 URL#xff08;例如 GitLab 或自定义应用#xff09;#xff0c;然后点击 Create new link。
2) 配置 Con…Jira配置应用程序链接
1) 创建应用程序链接
登录 JIRA 管理后台。转到 Administration Applications Application Links。在输入框中输入外部应用程序的 URL例如 GitLab 或自定义应用然后点击 Create new link。
2) 配置 Consumer Key 和 Public Key 在创建应用链接的过程中 Consumer Key自定义一个唯一的字符串标识应用程序例如 jira-oauth-client。Public Key需要将客户端的公钥粘贴到这里私钥用于客户端请求使用。 公钥的格式应为 PEM 格式示例如下 -----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnVOGkhN0P3y5FNceXGy
qYBl9cJpOyYsGnO94RtuOCmj/KFszDvn/dNqg2KjGvB5MgkHslZ8ZfZkXHZwIfB
...省略其余内容...
-----END PUBLIC KEY-----
3) 保存配置
确保填写的 Consumer Key 和 Public Key 在客户端代码中保持一致。保存链接。
提示在Jira中配置应用程序链接的【链入认证】时没有配置客户回调URL只配置了客户关键字(consumer_key)RSA加密公钥(public_key)
在 JIRA 中配置 应用程序链接Application Link 时如果没有 consumer_secret 值这其实是正常的情况。JIRA 的 OAuth 1.0a 认证机制只需要配置 Consumer Key 和 Public Key。 JIRA OAuth1为什么没有 consumer_secret OAuth 1.0a 认证 在 JIRA 的 OAuth 1.0a 实现中consumer_secret 并不是必需的部分。JIRA 使用 Consumer Key 来标识应用程序并通过 Public Key 验证签名。 与其他 OAuth 1.0a 实现不同JIRA 中的密钥对是基于 RSA 的公钥加密系统 Public Key 配置在 JIRA 中。Private Key 保存在客户端并用于签名请求。
python代码示例
import requests
from requests_oauthlib import OAuth1Session# 这些值来自你在 JIRA 上创建的 OAuth 应用
# 替换为你的 Consumer Key
consumer_key your-consumer-key
# 替换为你的 Consumer Secret我在调用调用jira接口认证时在jira中配置程序链接时没有地方配置这个secret因此这里可以空着不用生成OAuth1Session对象时也不传这个参数即可通过consumer_key判断请求客户端
consumer_secret your-consumer-secret# 私钥对应的公钥是配置在JIRA中的
PRIVATE_KEY
-----BEGIN RSA PRIVATE KEY-----
your_private_key_here
-----END RSA PRIVATE KEY-----
# 替换为你的 JIRA 实例 URL
jira_url https://your-jira-instance.atlassian.net# 请求 OAuth Token 的 URL
request_token_url f{jira_url}/plugins/servlet/oauth/request-token
authorize_url f{jira_url}/plugins/servlet/oauth/authorize
access_token_url f{jira_url}/plugins/servlet/oauth/access-token# 步骤 1: 获取请求令牌Request Token
oauth OAuth1Session(client_keyconsumer_key, rsa_keyprivate_key,signature_methodRSA-SHA1,callback_urioob)# 获取请求令牌和请求令牌的 URL
request_token_response oauth.fetch_request_token(request_token_url)# 解析返回的令牌信息
request_token request_token_response.get(oauth_token)
request_token_secret request_token_response.get(oauth_token_secret)print(fRequest Token: {request_token})
print(fRequest Token Secret: {request_token_secret})# 步骤 2: 用户授权
print(fGo to the following URL to authorize the application: {authorize_url}?oauth_token{request_token})
# 确保用户输入授权码
oauth_verifier input(Enter the verification code (oauth_verifier): ) # 步骤 3: 使用授权的 Token 获取访问令牌Access Token
# 传递 verifier 参数
oauth_tokens oauth.fetch_access_token(access_token_url, verifieroauth_verifier) access_token oauth_tokens.get(oauth_token)
access_token_secret oauth_tokens.get(oauth_token_secret)print(fAccess Token: {access_token})
print(fAccess Token Secret: {access_token_secret})遇到的问题
生成的JIRA授权URL没有verification code
点击程序生成的授权链接然后点击allow按钮后页面跳转后显示的信息如下
You have successfully authorised xxxx. Please close this browser window and click continue in the client.
这个信息里没有verification code跟之前用java程序生成的授权URL得到的信息不一样正确的信息应如下
You have successfully authorised xxxx. Your verification code is GPmbXd. You will need to enter this exact text when prompted. You should write this value down before closing the browser window.
通过对比原来的java程序和新写的python程序发现原来的java在获取request token中会设置callback oob
JiraOAuthGetTemporaryToken oauthGetTemporaryToken new JiraOAuthGetTemporaryToken(reuqestTokenUrl);// 设置RSA验签私钥
OAuthRsaSigner oauthRsaSigner new OAuthRsaSigner();
oauthRsaSigner.privateKey xxxxx
oauthGetTemporaryToken.consumerKey xxx
oauthGetTemporaryToken.signer oauthRsaSigner;oauthGetTemporaryToken.transport new ApacheHttpTransport();
//设置回调为oob
oauthGetTemporaryToken.callbackoob;
我们看下1.0和1.0a协议的一些要求
1.0协议中callback在oauth认证的第二步请求用户授权中通过url参数设置并明文传输。新的1.0a协议中callback作为oauth第一步获取request token的参数oauth_callback并参与到签名过程。此外当没有callback时callback值必须设为oobout-of-bound。Provider在返回request token的同时返回一个oauth_callback_confirmed参数其值为true表示Provider支持1.0a协议。用户完成授权后Provider在redirect到callback时提供一个新的oauth_verifier参数无法被猜测的随机字串该参数会被用在request token换取access token的过程中。如果callback值为oob那么Provider需要提供页面显示oauth_verifier参数值。而Consumer可以引导用户将这个参数值填入适当位置来完成授权
requests_oauthlib.oauth1_session.VerifierMissing: No client verifier has been set.
这个问题处理起来就比较简单了通过调试程序看到verification_code也的确传到fetch_access_token方法参数中了但是还是说没有设置verifier然后进入到oauth1_session.py代码中调试发现其对verifier的判断逻辑如下
if verifier:self._client.client.verifier verifier
if not getattr(self._client.client,verifier,None):raise VerifierMissing(No client verifier has been set.)
token self._fetch_token(url,**request_kwargs)
发现是参数名写的不对之前代码中参数设置是
oauth_tokens oauth.fetch_access_token(access_token_url, oauth_verifieroauth_verifier)
修改后参数设置是
oauth_tokens oauth.fetch_access_token(access_token_url, verifieroauth_verifier) 参考
OAuth协议更新到1.0a