我正在尝试建立一个连接到jira的网站以创建问题。 该网站需要向用户请求授权(使用OAuth1),然后连接到Jira。
当用户连接到/ loginjira时,网站将获取请求令牌,然后将用户重定向到新选项卡中的JIRA身份验证页面,同时将当前选项卡重定向到/ gettoken。 连接用户后,他可以关闭新标签(JIRA不会回调我的网站) 问题出在这里:一旦用户返回网站,我就无法获取访问令牌。
particlesJS('particles-js',
{
"particles": {
"number": {
"value": 200,
"density": {
"enable": true,
"value_area": 800
}
},
"color": {
"value": "#ff186a"
},
"shape": {
"type": "circle",
"stroke": {
"width": 0,
"color": "#ff186a"
},
"polygon": {
"nb_sides": 5
},
"image": {
"src": "img/github.svg",
"width": 100,
"height": 100
}
},
"opacity": {
"value": 0.5,
"random": false,
"anim": {
"enable": false,
"speed": 1,
"opacity_min": 0.1,
"sync": false
}
},
"size": {
"value": 5,
"random": true,
"anim": {
"enable": false,
"speed": 40,
"size_min": 0.1,
"sync": false
}
},
"line_linked": {
"enable": true,
"distance": 150,
"color": "#ff186a",
"opacity": 0.4,
"width": 1
},
"move": {
"enable": true,
"speed": 6,
"direction": "none",
"random": false,
"straight": false,
"out_mode": "out",
"attract": {
"enable": false,
"rotateX": 600,
"rotateY": 1200
}
}
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": {
"enable": true,
"mode": "repulse"
},
"onclick": {
"enable": true,
"mode": "push"
},
"resize": true
},
"modes": {
"grab": {
"distance": 400,
"line_linked": {
"opacity": 1
}
},
"bubble": {
"distance": 400,
"size": 40,
"duration": 2,
"opacity": 8,
"speed": 3
},
"repulse": {
"distance": 200
},
"push": {
"particles_nb": 4
},
"remove": {
"particles_nb": 2
}
}
},
"retina_detect": true,
"config_demo": {
"hide_card": false,
"background_color": "#b61924",
"background_image": "",
"background_position": "50% 50%",
"background_repeat": "no-repeat",
"background_size": "cover"
}
}
我找不到让flask在两个视图之间“保存” oauth1session对象的方法-例如。一旦用户接受了请求令牌,就获取访问令牌。
我知道
def request_token():
f = open(auth.root_path + '\\rsa.pem', 'r')
secret = f.read()
f.close()
request_token_url = 'https://website.com/jira/plugins/servlet/oauth/request-token'
authorize_url = 'https://website.com/jira/plugins/servlet/oauth/authorize'
oauth = OAuth1Session('oAuthKey',
signature_type='auth_header',
signature_method=SIGNATURE_RSA,
verifier="jira_verifier",
rsa_key=secret)
request_token = oauth.fetch_request_token(request_token_url)
session['request_token'] = request_token
url = authorize_url + '?oauth_token=' + request_token['oauth_token']
return render_template('login.html', url=url)
@auth.route('/loginjira')
def loginjira():
session.permanent = True
if 'access_token' not in session:
return request_token()
return render_template('display.html', url=url)
@auth.route('/gettoken')
def get_token():
f = open(auth.root_path + '\\rsa.pem', 'r')
secret = f.read()
f.close()
oauth = OAuth1Session('oAuthKey',
signature_type='auth_header',
signature_method=SIGNATURE_RSA,
verifier="jira_verifier",
rsa_key=secret)
access_url = 'https://website.com/jira/plugins/servlet/oauth/access-token'
access_token = oauth.fetch_access_token(access_url)
jira = JIRA(options={'server': "https://website.com/jira/"}, oauth={
'access_token': access_token['oauth_token'],
'access_token_secret': access_token['oauth_token_secret'],
'consumer_key': "oAuthKey",
'key_cert': secret
})
issue = jira.issue('ISSUE-ID')
print("issue: " + issue.fields.summary)
我在寻找一种方法来在每个客户端上具有持久的oauth会话服务器端,但是找不到方法。
有人做过类似的事情吗?