Module supertokens_python.recipe.openid
Expand source code
# Copyright (c) 2021, VRAI Labs and/or its affiliates. All rights reserved.
#
# This software is licensed under the Apache License, Version 2.0 (the
# "License") as published by the Apache Software Foundation.
#
# You may not use this file except in compliance with the License. You may
# obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import annotations
from typing import TYPE_CHECKING, Union
from .recipe import OpenIdRecipe
from .utils import InputOverrideConfig, OpenIdOverrideConfig
if TYPE_CHECKING:
from supertokens_python.supertokens import RecipeInit
def init(
issuer: Union[str, None] = None,
override: Union[OpenIdOverrideConfig, None] = None,
) -> RecipeInit:
return OpenIdRecipe.init(issuer, override)
__all__ = [
"InputOverrideConfig", # deprecated, use OpenIdOverrideConfig instead
"OpenIdOverrideConfig",
"OpenIdRecipe",
"init",
]
Sub-modules
supertokens_python.recipe.openid.apisupertokens_python.recipe.openid.asynciosupertokens_python.recipe.openid.constantssupertokens_python.recipe.openid.exceptionssupertokens_python.recipe.openid.interfacessupertokens_python.recipe.openid.recipesupertokens_python.recipe.openid.recipe_implementationsupertokens_python.recipe.openid.synciosupertokens_python.recipe.openid.utils
Functions
def init(issuer: Union[str, None] = None, override: Union[BaseOverrideConfig[RecipeInterface, APIInterface], None] = None)
Classes
class InputOverrideConfig (**data: Any)-
Base class for input override config with API overrides.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.Ancestors
- BaseOverrideConfig
- BaseOverrideConfigWithoutAPI
- CamelCaseBaseModel
- APIResponse
- abc.ABC
- pydantic.main.BaseModel
- typing.Generic
Class variables
var model_config-
The type of the None singleton.
class OpenIdOverrideConfig (**data: Any)-
Base class for input override config with API overrides.
Create a new model by parsing and validating input data from keyword arguments.
Raises [
ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.selfis explicitly positional-only to allowselfas a field name.Ancestors
- BaseOverrideConfig
- BaseOverrideConfigWithoutAPI
- CamelCaseBaseModel
- APIResponse
- abc.ABC
- pydantic.main.BaseModel
- typing.Generic
Inherited members
class OpenIdRecipe (recipe_id: str, app_info: AppInfo, config: OpenIdConfig)-
Helper class that provides a standard way to create an ABC using inheritance.
Expand source code
class OpenIdRecipe(RecipeModule): recipe_id = "openid" __instance = None def __init__( self, recipe_id: str, app_info: AppInfo, config: OpenIdConfig, ): from supertokens_python.recipe.jwt import JWTRecipe super().__init__(recipe_id, app_info) self.config = validate_and_normalise_user_input( app_info=app_info, config=config ) self.jwt_recipe = JWTRecipe.get_instance() recipe_implementation = RecipeImplementation( Querier.get_instance(recipe_id), self.config, app_info, ) self.recipe_implementation = self.config.override.functions( recipe_implementation ) api_implementation = APIImplementation() self.api_implementation = self.config.override.apis(api_implementation) def get_apis_handled(self) -> List[APIHandled]: return [ APIHandled( method="get", path_without_api_base_path=NormalisedURLPath(GET_DISCOVERY_CONFIG_URL), request_id=GET_DISCOVERY_CONFIG_URL, disabled=self.api_implementation.disable_open_id_discovery_configuration_get, ) ] + self.jwt_recipe.get_apis_handled() async def handle_api_request( self, request_id: str, tenant_id: str, request: BaseRequest, path: NormalisedURLPath, method: str, response: BaseResponse, user_context: Dict[str, Any], ): options = APIOptions( request, response, self.get_recipe_id(), self.config, self.recipe_implementation, ) if request_id == GET_DISCOVERY_CONFIG_URL: return await open_id_discovery_configuration_get( self.api_implementation, options, user_context ) return await self.jwt_recipe.handle_api_request( request_id, tenant_id, request, path, method, response, user_context ) async def handle_error( self, request: BaseRequest, err: SuperTokensError, response: BaseResponse, user_context: Dict[str, Any], ): if isinstance(err, SuperTokensOpenIdError): raise err return await self.jwt_recipe.handle_error(request, err, response, user_context) def get_all_cors_headers(self) -> List[str]: return self.jwt_recipe.get_all_cors_headers() def is_error_from_this_recipe_based_on_instance(self, err: Exception) -> bool: return isinstance(err, SuperTokensError) and ( isinstance(err, SuperTokensOpenIdError) or self.jwt_recipe.is_error_from_this_recipe_based_on_instance(err) ) @staticmethod def init( issuer: Union[str, None] = None, override: Union[OpenIdOverrideConfig, None] = None, ): from supertokens_python.plugins import OverrideMap, apply_plugins config = OpenIdConfig( issuer=issuer, override=override, ) def func(app_info: AppInfo, plugins: List[OverrideMap]): if OpenIdRecipe.__instance is None: OpenIdRecipe.__instance = OpenIdRecipe( recipe_id=OpenIdRecipe.recipe_id, app_info=app_info, config=apply_plugins( recipe_id=OpenIdRecipe.recipe_id, config=config, plugins=plugins, ), ) return OpenIdRecipe.__instance raise_general_exception( "OpenId recipe has already been initialised. Please check your code for bugs." ) return func @staticmethod def get_instance() -> OpenIdRecipe: if OpenIdRecipe.__instance is not None: return OpenIdRecipe.__instance raise_general_exception( "Initialisation not done. Did you forget to call the SuperTokens.init function?" ) @staticmethod def reset(): if ("SUPERTOKENS_ENV" not in environ) or ( environ["SUPERTOKENS_ENV"] != "testing" ): raise_general_exception("calling testing function in non testing env") OpenIdRecipe.__instance = None @staticmethod async def get_issuer(user_context: Dict[str, Any]) -> str: open_id_config = await OpenIdRecipe.get_instance().recipe_implementation.get_open_id_discovery_configuration( user_context ) return open_id_config.issuerAncestors
- RecipeModule
- abc.ABC
Class variables
var recipe_id-
The type of the None singleton.
Static methods
def get_instance() ‑> OpenIdRecipeasync def get_issuer(user_context: Dict[str, Any]) ‑> strdef init(issuer: Union[str, None] = None, override: Union[BaseOverrideConfig[RecipeInterface, APIInterface], None] = None)def reset()
Methods
def get_all_cors_headers(self) ‑> List[str]def get_apis_handled(self) ‑> List[APIHandled]async def handle_api_request(self, request_id: str, tenant_id: str, request: BaseRequest, path: NormalisedURLPath, method: str, response: BaseResponse, user_context: Dict[str, Any])async def handle_error(self, request: BaseRequest, err: SuperTokensError, response: BaseResponse, user_context: Dict[str, Any])def is_error_from_this_recipe_based_on_instance(self, err: Exception) ‑> bool
Inherited members