Hydra

  • Identity Charmers
Channel Revision Published Runs on
latest/stable 276 24 Apr 2024
Ubuntu 22.04
latest/edge 320 20 Oct 2024
Ubuntu 22.04
0.3/edge 320 07 Nov 2024
Ubuntu 22.04
0.2/stable 285 26 Jun 2024
Ubuntu 22.04
0.2/edge 285 09 May 2024
Ubuntu 22.04
0.1/edge 270 24 Nov 2023
Ubuntu 22.04
juju deploy hydra
Show information

Platform:

charms.hydra.v0.oauth

Oauth Library.

This library is designed to enable applications to register OAuth2/OIDC clients with an OIDC Provider through the oauth interface.

Getting started

To get started using this library you just need to fetch the library using charmcraft. Note that you also need to add jsonschema to your charm's requirements.txt.

cd some-charm
charmcraft fetch-lib charms.hydra.v0.oauth
EOF

Then, to initialize the library:

# ...
from charms.hydra.v0.oauth import ClientConfig, OAuthRequirer

OAUTH = "oauth"
OAUTH_SCOPES = "openid email"
OAUTH_GRANT_TYPES = ["authorization_code"]

class SomeCharm(CharmBase):
  def __init__(self, *args):
    # ...
    self.oauth = OAuthRequirer(self, client_config, relation_name=OAUTH)

    self.framework.observe(self.oauth.on.oauth_info_changed, self._configure_application)
    # ...

    def _on_ingress_ready(self, event):
        self.external_url = "https://example.com"
        self._set_client_config()

    def _set_client_config(self):
        client_config = ClientConfig(
            urljoin(self.external_url, "/oauth/callback"),
            OAUTH_SCOPES,
            OAUTH_GRANT_TYPES,
        )
        self.oauth.update_client_config(client_config)

Index

class ClientConfigError

Description

Emitted when invalid client config is provided. None

class DataValidationError

Description

Raised when data validation fails on relation data. None

def strtobool(val: str)

Convert a string representation of truth to true (1) or false (0).

Description

True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if 'val' is anything else.

class OAuthRelation

Description

A class containing helper methods for oauth relation. None

Methods

class ClientConfig

Description

Helper class containing a client's configuration. None

Methods

ClientConfig. validate( self )

Description

Validate the client configuration. None

ClientConfig. to_dict( self )

Description

Convert object to dict. None

class OauthProviderConfig

Description

Helper class containing provider's configuration. None

Methods

OauthProviderConfig. from_dict( cls , dic: Dict )

Description

Generate OauthProviderConfig instance from dict. None

class OAuthInfoChangedEvent

Description

Event to notify the charm that the information in the databag changed. None

Methods

OAuthInfoChangedEvent. __init__( self , handle: Handle , client_id: str , client_secret_id: str )

OAuthInfoChangedEvent. snapshot( self )

Description

Save event. None

OAuthInfoChangedEvent. restore( self , snapshot: Dict )

Description

Restore event. None

class InvalidClientConfigEvent

Description

Event to notify the charm that the client configuration is invalid. None

Methods

InvalidClientConfigEvent. __init__( self , handle: Handle , error: str )

InvalidClientConfigEvent. snapshot( self )

Description

Save event. None

InvalidClientConfigEvent. restore( self , snapshot: Dict )

Description

Restore event. None

class OAuthInfoRemovedEvent

Description

Event to notify the charm that the provider data was removed. None

Methods

OAuthInfoRemovedEvent. snapshot( self )

Description

Save event. None

OAuthInfoRemovedEvent. restore( self , snapshot: Dict )

Description

Restore event. None

class OAuthRequirerEvents

Description

Event descriptor for events raised by OAuthRequirerEvents. None

class OAuthRequirer

Description

Register an oauth client. None

Methods

OAuthRequirer. __init__( self , charm: CharmBase , client_config , relation_name: str )

OAuthRequirer. is_client_created( self , relation_id )

Description

Check if the client has been created. None

OAuthRequirer. get_provider_info( self , relation_id )

Description

Get the provider information from the databag. None

OAuthRequirer. get_client_secret( self , client_secret_id: str )

Description

Get the client_secret. None

OAuthRequirer. update_client_config( self , client_config: ClientConfig , relation_id )

Description

Update the client config stored in the object. None

class ClientCreatedEvent

Description

Event to notify the Provider charm to create a new client. None

Methods

ClientCreatedEvent. __init__( self , handle: Handle , redirect_uri: str , scope: str , grant_types , audience: List , token_endpoint_auth_method: str , relation_id: int )

ClientCreatedEvent. snapshot( self )

Description

Save event. None

ClientCreatedEvent. restore( self , snapshot: Dict )

Description

Restore event. None

ClientCreatedEvent. to_client_config( self )

Description

Convert the event information to a ClientConfig object. None

class ClientChangedEvent

Description

Event to notify the Provider charm that the client config changed. None

Methods

ClientChangedEvent. __init__( self , handle: Handle , redirect_uri: str , scope: str , grant_types: List , audience: List , token_endpoint_auth_method: str , relation_id: int , client_id: str )

ClientChangedEvent. snapshot( self )

Description

Save event. None

ClientChangedEvent. restore( self , snapshot: Dict )

Description

Restore event. None

ClientChangedEvent. to_client_config( self )

Description

Convert the event information to a ClientConfig object. None

class ClientDeletedEvent

Description

Event to notify the Provider charm that the client was deleted. None

Methods

ClientDeletedEvent. __init__( self , handle: Handle , relation_id: int )

ClientDeletedEvent. snapshot( self )

Description

Save event. None

ClientDeletedEvent. restore( self , snapshot: Dict )

Description

Restore event. None

class OAuthProviderEvents

Description

Event descriptor for events raised by OAuthProviderEvents. None

class OAuthProvider

Description

A provider object for OIDC Providers. None

Methods

OAuthProvider. __init__( self , charm: CharmBase , relation_name: str )

OAuthProvider. set_provider_info_in_relation_data( self , issuer_url: str , authorization_endpoint: str , token_endpoint: str , introspection_endpoint: str , userinfo_endpoint: str , jwks_endpoint: str , scope: str , groups , ca_chain , jwt_access_token )

Description

Put the provider information in the databag. None

OAuthProvider. set_client_credentials_in_relation_data( self , relation_id: int , client_id: str , client_secret: str )

Description

Put the client credentials in the databag. None