Kratos External Idp Integrator
- Identity Charmers
Channel | Revision | Published | Runs on |
---|---|---|---|
latest/edge | 258 | 20 Oct 2024 | |
0.2/stable | 192 | 26 Jun 2024 | |
0.2/edge | 192 | 01 May 2024 | |
0.1/edge | 182 | 15 Sep 2023 |
juju deploy kratos-external-idp-integrator --channel edge
Deploy universal operators easily with Juju, the Universal Operator Lifecycle Manager.
Platform:
charms.kratos_external_idp_integrator.v0.kratos_external_provider
-
- Last updated 11 Sep 2024
- Revision Library version 0.10
Interface library for Kratos external OIDC providers.
This library wraps relation endpoints using the kratos-external-idp
interface
and provides a Python API for both requesting Kratos to register the client credentials
and for communicating with an external provider.
Getting Started
To get started using the library, you just need to fetch the library using charmcraft
.
cd some-charm
charmcraft fetch-lib charms.kratos_external_idp_integrator.v0.kratos_external_provider
To use the library from the provider side (KratosExternalIdpIntegrator):
In the metadata.yaml
of the charm, add the following:
provides:
kratos-external-idp:
interface: external_provider
limit: 1
Then, to initialise the library:
from charms.kratos_external_idp_integrator.v0.kratos_external_provider import (
ExternalIdpProvider, InvalidConfigError
)
from ops.model import BlockedStatus
class SomeCharm(CharmBase):
def __init__(self, *args):
# ...
self.external_idp_provider = ExternalIdpProvider(self, self.config)
self.framework.observe(self.on.config_changed, self._on_config_changed)
self.framework.observe(self.external_idp_provider.on.ready, self._on_ready)
self.framework.observe(
self.external_idp_provider.on.redirect_uri_changed, self._on_redirect_uri_changed
)
def _on_config_changed(self, event):
# ...
try:
self.external_idp_provider.validate_provider_config(self.config)
except InvalidConfigError as e:
self.unit.status = BlockedStatus(f"Invalid configuration: {e.args[0]}")
# ...
def _on_redirect_uri_changed(self, event):
logger.info(f"The client's redirect_uri changed to {event.redirect_uri}")
self._stored.redirect_uri = event.redirect_uri
self._on_update_status(event)
def _on_ready(self, event):
if not isinstance(self.unit.status, BlockedStatus):
self.external_idp_provider.create_provider(self.config)
To use the library from the requirer side (Kratos):
In the metadata.yaml
of the charm, add the following:
requires:
kratos-external-idp:
interface: external_provider
Then, to initialise the library:
from charms.kratos_external_idp_integrator.v0.kratos_external_provider import (
ExternalIdpRequirer
)
class KratosCharm(CharmBase):
def __init__(self, *args):
# ...
self.external_idp_requirer = ExternalIdpRequirer(self)
self.framework.observe(
self.external_idp_provider.on.client_config_changed, self._on_client_config_changed
)
def _on_client_config_changed(self, event):
self._configure(event)
self.external_provider.set_relation_registered_provider(
some_redirect_uri, event.provider_id, event.relation_id
)
Index
class InvalidConfigError
Description
Internal exception that is raised if the charm config is not valid. None
class DataValidationError
Description
Raised when data validation fails on relation data. None
class BaseProviderConfigHandler
Description
The base class for parsing a provider's config. None
Methods
BaseProviderConfigHandler. validate_config( cls , config: Mapping )
Description
Validate and sanitize the user provided config. None
BaseProviderConfigHandler. handle_config( cls , config: Mapping )
Description
Validate the config and transform it in the relation databag expected format. None
BaseProviderConfigHandler. parse_config( cls , config: Dict )
Description
Parse the user provided config into the relation databag expected format. None
class GenericConfigHandler
Description
The class for parsing a 'generic' provider's config. None
Methods
class SocialConfigHandler
Description
The class for parsing a social provider's config. None
Methods
class MicrosoftConfigHandler
Description
The class for parsing a 'microsoft' provider's config. None
Methods
class GithubConfigHandler
Description
The class for parsing a 'github' provider's config. None
class AppleConfigHandler
Description
The class for parsing an 'apple' provider's config. None
Methods
def get_provider_config_handler(config: Mapping)
Description
Get the config handler for this provider. None
class RelationReadyEvent
Description
Event to notify the charm that the relation is ready. None
Methods
RelationReadyEvent. snapshot( self )
Description
Save event. None
RelationReadyEvent. restore( self , snapshot: Dict )
Description
Restore event. None
class RedirectURIChangedEvent
Description
Event to notify the charm that the redirect_uri changed. None
Methods
RedirectURIChangedEvent. __init__( self , handle: Handle , redirect_uri: str )
RedirectURIChangedEvent. snapshot( self )
Description
Save redirect_uri. None
RedirectURIChangedEvent. restore( self , snapshot: Dict )
Description
Restore redirect_uri. None
class ExternalIdpProviderEvents
Description
Event descriptor for events raised by ExternalIdpProvider
. None
class ExternalIdpProvider
Description
Forward client configurations to Identity Broker. None
Methods
ExternalIdpProvider. __init__( self , charm: CharmBase , relation_name: str )
ExternalIdpProvider. is_ready( self )
Description
Checks if the relation is ready. None
ExternalIdpProvider. create_provider( self , config: Mapping )
Description
Use the configuration to create the relation databag. None
ExternalIdpProvider. remove_provider( self )
Description
Remove the provider config to the relation databag. None
ExternalIdpProvider. get_redirect_uri( self , relation_id )
Description
Get the kratos client's redirect_uri. None
ExternalIdpProvider. validate_provider_config( self , config: Mapping )
Validate the provider config.
Description
Raises InvalidConfigError if config is invalid.
class Provider
Description
Class for describing an external provider. None
Methods
Provider. provider_id( self )
Description
Returns a unique ID for the client credentials of the provider. None
Provider. provider_id( self , val )
Provider. get_scope( self )
Provider. get_microsoft_tenant( self )
Provider. config( self )
Description
Generate Kratos config for this provider. None
Provider. from_dict( cls , dic: Dict )
Description
Generate Provider instance from dict. None
class ClientConfigChangedEvent
Description
Event to notify the charm that a provider's client config changed. None
Methods
ClientConfigChangedEvent. __init__( self , handle: Handle , provider: Provider )
ClientConfigChangedEvent. snapshot( self )
Description
Save event. None
ClientConfigChangedEvent. restore( self , snapshot: Dict )
Description
Restore event. None
class ClientConfigRemovedEvent
Description
Event to notify the charm that a provider's client config was removed. None
Methods
ClientConfigRemovedEvent. __init__( self , handle: Handle , relation_id: str )
ClientConfigRemovedEvent. snapshot( self )
Description
Save event. None
ClientConfigRemovedEvent. restore( self , snapshot: Dict )
Description
Restore event. None
class ExternalIdpRequirerEvents
Description
Event descriptor for events raised by ExternalIdpRequirerEvents
. None
class ExternalIdpRequirer
Description
Receive the External Idp configurations for Kratos. None
Methods
ExternalIdpRequirer. __init__( self , charm: CharmBase , relation_name: str )
ExternalIdpRequirer. set_relation_registered_provider( self , redirect_uri: str , provider_id: str , relation_id: int )
Description
Update the relation databag. None
ExternalIdpRequirer. remove_relation_registered_provider( self , relation_id: int )
Description
Delete the provider info from the databag. None
ExternalIdpRequirer. get_providers( self )
Description
Iterate over the relations and fetch all providers. None