Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add access token argument to oidc-register command #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion flask_oidc/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def __init__(self, response):


# OpenID Connect Dynamic Client Registration 1.0
def register_client(provider_info, redirect_uris):
def register_client(provider_info, redirect_uris, access_token=None):
"""
This function registers a new client with the specified OpenID Provider,
and then returns the regitered client ID and other information.
Expand All @@ -100,6 +100,9 @@ def register_client(provider_info, redirect_uris):
:param redirect_uris: The redirect URIs the application wants to
register.
:type redirect_uris: list
:param access_token: Bearer token to access the client registration API
of the OpenID Provider.
:type access_token: str, optional
:returns: An object containing the information needed to configure the
actual client code to communicate with the OpenID Provider.
:rtype: dict
Expand All @@ -116,6 +119,8 @@ def register_client(provider_info, redirect_uris):
'token_endpoint_auth_method': 'client_secret_post'}

headers = {'Content-type': 'application/json'}
if access_token:
headers['Authorization'] = 'Bearer {}'.format(access_token)

resp, content = httplib2.Http().request(
provider_info['registration_endpoint'], 'POST',
Expand Down
6 changes: 5 additions & 1 deletion flask_oidc/registration_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def _parse_args():
help='Base URL to the application')
parser.add_argument('--token-introspection-uri',
help='Token introspection URI')
parser.add_argument('--access-token',
help='Initial access token or bearer token')
parser.add_argument('--output-file', default='client_secrets.json',
help='File to write client info to')
parser.add_argument('--debug', action='store_true')
Expand Down Expand Up @@ -71,8 +73,10 @@ def main():
return 1
if args.debug:
print('Provider info: %s' % OP)
access_token = args.access_token or None
try:
reg_info = registration.register_client(OP, redirect_uris)
reg_info = registration.register_client(OP, redirect_uris,
access_token=access_token)
except Exception as ex:
print('Error registering client')
if args.debug:
Expand Down