Skip to content

Commit

Permalink
feat(connector): implement header authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
dovahcrow committed Sep 24, 2020
1 parent dff0844 commit d879c20
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions dataprep/connector/schema/defs.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ def build(
params: Dict[str, Any],
storage: Optional[Dict[str, Any]] = None, # pylint: disable=unused-argument
) -> None:
"""Populate some required fields to the request data.
Complex logic may also happens in this function (e.g. start a server to do OAuth).
"""
"""Populate some required fields to the request data."""

req_data["params"][self.key_param] = params["access_token"]


Expand All @@ -100,14 +99,33 @@ def build(
params: Dict[str, Any],
storage: Optional[Dict[str, Any]] = None, # pylint: disable=unused-argument
) -> None:
"""Populate some required fields to the request data.
Complex logic may also happens in this function (e.g. start a server to do OAuth).
"""
"""Populate some required fields to the request data."""

req_data["headers"]["Authorization"] = f"Bearer {params['access_token']}"


class HeaderAuthorizationDef(BaseDef):
type: str = Field("Header", const=True)
key_name: str
extra: Dict[str, str] = Field(default_factory=dict)

def build(
self,
req_data: Dict[str, Any],
params: Dict[str, Any],
storage: Optional[Dict[str, Any]] = None, # pylint: disable=unused-argument
) -> None:
"""Populate some required fields to the request data."""

req_data["headers"][self.key_name] = params["access_token"]
req_data["headers"].update(self.extra)


AuthorizationDef = Union[
OAuth2AuthorizationDef, QueryParamAuthorizationDef, BearerAuthorizationDef
OAuth2AuthorizationDef,
QueryParamAuthorizationDef,
BearerAuthorizationDef,
HeaderAuthorizationDef,
]


Expand Down

0 comments on commit d879c20

Please sign in to comment.