Credential Data Source
This is an interface that defines the factory class responsible for creating Credential instances that represent a unique Token, ensuring that only a single unique Credential instance exists at runtime for its Token.
Furthermore, since a Credential contains both a Token and an OAuth2Client (which is used for performing OAuth2 operations), depending on the environment, the datasource may be responsible for defining the network interface (e.g. URLSession) used for those network operations.
Primary workflows
All of these workflows should be performed in a thread-safe or synchronized fashion.
Fetch credential for a token
This is the primary capability the datasource is used for, which is to return an instance of Credential that matches the given token.
The CredentialCoordinator calls this from several workflows, including:
- Storing a token
- Finding a credential by ID
- Filtering credentials based on a closure
Removing a credential
When the CredentialCoordinator removes a Credential or Token from storage, it first needs to remove the credential instance from the datasource so references to that token can be deleted or garbage collected.
Count of credentials
Returns the number of credentials currently cached and resident in memory.
Check if a credential is cached
This is used to determine if the datasource currently is caching a Credential that matches the supplied token.