Pyjo.AWS.Credentials.SSO - Credentials of IAM Identity Center

from Pyjo.AWS.Credentials.SSO import SSO

credentials = SSO().credentials()

# Or import the module, as in Google Python Style Guide

import Pyjo.AWS.Config
import Pyjo.AWS.Credentials.SSO

provider = Pyjo.AWS.Credentials.SSO.new(config=Pyjo.AWS.Config.new(profile='dev'))
provider.credentials_p().then(lambda credentials: print(credentials.expiration)).wait()

Pyjo.AWS.Credentials.SSO is the provider of the credentials of a role of IAM Identity Center, the former AWS SSO, of a profile of the shared files of Pyjo.AWS.Config, after aws sso login, as the SDKs of AWS get them: the token of the login, of the cache of the AWS CLI in ~/.aws/sso/cache, gets the credentials of the role of sso_role_name in the account of sso_account_id with GetRoleCredentials of SSO.

A profile of a section sso-session, which aws configure sso writes, has a token that is refreshed with CreateToken of SSO OIDC before it expires, and written back to the cache, as the AWS CLI does:

[profile dev]
sso_session = company
sso_account_id = 123456789012
sso_role_name = ReadOnly

[sso-session company]
sso_start_url = https://company.awsapps.com/start
sso_region = eu-central-1
sso_registration_scopes = sso:account:access

A legacy profile, with sso_start_url and sso_region of its own, has a token that is not refreshed, and expires after the hours of the session of IAM Identity Center.

A token that is not in the cache, or has expired, is an error, which tells to run aws sso login.

See also

Pyjo.AWS.Credentials.Provider, Pyjo.AWS.Credentials.Profile, Pyjo.AWS.Client, https://docs.aws.amazon.com/sdkref/latest/guide/feature-sso-credentials.html.

Classes

class Pyjo.AWS.Credentials.SSO.Pyjo_AWS_Credentials_SSO(*, config: Pyjo_AWS_Config | None = None, profile: str | None = None, cache_dir: str | None = None, **kwargs: Any)[source]

Pyjo.AWS.Credentials.SSO inherits all attributes and methods from Pyjo.AWS.Credentials.Provider and implements the following new ones.

__init__(*, config: Pyjo_AWS_Config | None = None, profile: str | None = None, cache_dir: str | None = None, **kwargs: Any) → None[source]
provider = Pyjo.AWS.Credentials.SSO.new()
provider = Pyjo.AWS.Credentials.SSO.new(config=Pyjo.AWS.Config.new(profile='dev'))
provider = Pyjo.AWS.Credentials.SSO.new(profile='dev', cache_dir='/tmp/sso')

Construct a new Pyjo.AWS.Credentials.SSO object, with the options of Pyjo.AWS.Credentials.Provider.

cache_dir
path = provider.cache_dir

The Pyjo.File object of the directory of the cache of the tokens, ~/.aws/sso/cache of the AWS CLI by default.

cache_file(key: str) → Pyjo_File[source]
path = provider.cache_file('company')
path = provider.cache_file('https://company.awsapps.com/start')

The file of the token of the name of a section sso-session, or of the start URL of a legacy profile, in cache_dir, of the SHA-1 of the key, as the AWS CLI names it.

config
config = provider.config

The shared files, a new Pyjo.AWS.Config object by default.

async fetch() → Pyjo_AWS_Credentials | None[source]
credentials = await provider.fetch()

The credentials of the role of the profile, or None of a profile without SSO.

profile
name = provider.profile

The name of the profile, the profile of config by default.