Skip to content

Commit

Permalink
feat(bearer_request): support GET as auth-method + make 'service' and…
Browse files Browse the repository at this point in the history
… 'scope' optional arguments to auth request
  • Loading branch information
spk83 committed Dec 26, 2018
1 parent 9d5fab2 commit f4ba381
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,25 @@ def bearer_request(self, method, url, auth, **kwargs):
pprint.pprint(oauth['bearer'])

# print('[info] retreiving bearer token for {0}'.format(oauth['bearer']['scope']))
request_url = '{0}?service={1}&scope={2}'.format(oauth['bearer']['realm'],
oauth['bearer']['service'],
oauth['bearer']['scope'])
request_url = '{0}'.format(oauth['bearer']['realm'])
query_separator = '?'
if 'service' in oauth['bearer']:
request_url += '{0}service={1}'.format(query_separator, oauth['bearer']['service'])
query_separator = '&'
if 'scope' in oauth['bearer']:
request_url += '{0}scope={1}'.format(query_separator, oauth['bearer']['scope'])

if DEBUG:
print('[debug][auth][request] Refreshing auth token: POST {0}'.format(request_url))

try_oauth = requests.post(request_url, auth=auth, **kwargs)
if args.auth_method == 'GET':
try_oauth = requests.get(request_url, auth=auth, **kwargs)
else:
try_oauth = requests.post(request_url, auth=auth, **kwargs)

try:
token = ast.literal_eval(try_oauth._content)['token']
oauth_response = ast.literal_eval(try_oauth._content.decode('utf-8'))
token = oauth_response['access_token'] if 'access_token' in oauth_response else oauth_response['token']
except SyntaxError:
print('\n\n[ERROR] couldnt accure token: {0}'.format(try_oauth._content))
sys.exit(1)
Expand Down Expand Up @@ -532,7 +540,12 @@ def parse_args(args=None):
default='HEAD',
metavar="HEAD|GET"
)

parser.add_argument(
'--auth-method',
help=('Use POST or GET to get JWT tokens'),
default='POST',
metavar="POST|GET"
)
return parser.parse_args(args)


Expand Down

0 comments on commit f4ba381

Please sign in to comment.