def register_oauth_flow():
"""Register URIs used for OAuth flow."""
# https://developer.github.com/v3/oauth/
httpretty.register_uri(
httpretty.GET,
'https://github.com/login/oauth/authorize',
status=200,
body='User required to accept/reject scopes on this page'
)
def access_token_callback(request, uri, headers):
assert request.method == 'POST'
parsed_body = request.parse_request_body(request.body)
assert 'client_id' in parsed_body
assert 'client_secret' in parsed_body
assert 'code' in parsed_body
assert 'redirect_uri' in parsed_body
if parsed_body['code'][0] == 'bad_verification_code':
body = dict(
error_uri='http://developer.github.com/v3/oauth/'
'#bad-verification-code',
error_description='The code passed is '
'incorrect or expired.',
error='bad_verification_code',
)
else:
body = dict(
access_token='%s_token' % parsed_body['code'][0],
scope='admin:repo_hook,user:email',
token_type='bearer',
)
headers['content-type'] = 'application/x-www-form-urlencoded'
return (
200,
headers,
urllib_parse.urlencode(body)
)
httpretty.register_uri(
httpretty.POST,
'https://github.com/login/oauth/access_token',
body=access_token_callback,
)
评论列表
文章目录