-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '0.3_configurable_client'
- Loading branch information
Showing
13 changed files
with
681 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,4 +137,5 @@ dmypy.json | |
# Cython debug symbols | ||
cython_debug/ | ||
|
||
.vscode/ | ||
.vscode/ | ||
.scannerwork |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
|
||
from flask_oidc import registration, discovery | ||
import json | ||
from httplib2 import RelativeURIError | ||
from typing import Optional | ||
|
||
|
||
class ClientHandler: | ||
__client_url = None | ||
__client_id = None | ||
__client_secret = None | ||
__metadata_url= None | ||
__op_url = None | ||
op_data = None | ||
|
||
def __init__(self, op_url: str, client_url: str): | ||
"""[intializes] | ||
:param op_url: [url from oidc provider starting with https] | ||
:type op_url: str | ||
:param client_url: [url from client starting with https] | ||
:type client_url: str | ||
""" | ||
self.__op_url = op_url | ||
self.__client_url = client_url | ||
self.__metadata_url = '%s/.well-known/openid-configuration' % op_url | ||
self.op_data = self.discover(op_url) | ||
self.reg_info = self.register_client(op_data=self.op_data,client_url=client_url) | ||
print(self.reg_info) | ||
self.__client_id = self.reg_info['web']['client_id'] | ||
self.__client_secret = self.reg_info['web']['client_secret'] | ||
|
||
|
||
|
||
def get_client_dict(self) -> dict: | ||
r = { | ||
'op_metadata_url' : self.__metadata_url, | ||
'client_id' : self.__client_id, | ||
'client_secret' : self.__client_secret | ||
} | ||
|
||
return r | ||
|
||
|
||
def register_client(self, op_data: Optional[dict]=op_data, client_url: Optional[str]=__client_url) -> dict: | ||
"""[register client and returns client information] | ||
:param op_data: [description] | ||
:type op_data: dict | ||
:param client_url: [description] | ||
:type client_url: str | ||
:return: [client information including client-id and secret] | ||
:rtype: dict | ||
""" | ||
redirect_uri = '%s/oidc_callback' % client_url | ||
reg_info = registration.register_client(op_data, [redirect_uri]) | ||
return reg_info | ||
|
||
def discover(self, op_url: Optional[str]=__op_url, disc:discovery=discovery) -> dict : | ||
"""Discover op information on .well-known/open-id-configuration | ||
:param op_url: [description], defaults to __op_url | ||
:type op_url: str, optional | ||
:param discovery: [flask_oidc.discovery injection], defaults to discovery | ||
:type discovery: discovery, optional | ||
:return: [data retrieved from OP url] | ||
:rtype: dict3 | ||
""" | ||
|
||
op_data = {} | ||
try: | ||
op_data = disc.discover_OP_information(op_url) | ||
# print(op_data) | ||
return op_data | ||
|
||
except json.JSONDecodeError as err: | ||
print('Error trying to decode JSON: %s' % err) | ||
|
||
except RelativeURIError as err: | ||
print(err) | ||
|
||
except Exception as e: | ||
print('An unexpected ocurred: %s' % e) | ||
|
||
return op_data | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.