Authentication
Last updated
Was this helpful?
Last updated
Was this helpful?
To interact with the LearnCard Network API, you can choose one of two ways to authenticate:
Using the LearnCard Network Plugin (@learncard/network-plugin
) which handles authentication for you. (Preferred option)
Using for authentication with API endpoints. (recommended for implementations using REST endpoints).
Directly through the API endpoints using challenge-based DID Authentication. (most complex)
To authenticate using the LearnCard Network Plugin (@learncard/network-plugin
), first install the package:
Then, either instantiate a LearnCard Network enabled LearnCard, or add the Network Plugin to an existing LearnCard:
When using the LearnCard Network Plugin, challenge-based DID Authentication is handled for you, so no further steps are necessary.
Profile management uses DID-based authentication with a challenge-response mechanism and scope-based authorization.
Simple High-Level Auth Flow:
Granular Auth Flow:
If you choose to use the API endpoints directly, you'll need to manage challenge-based DID Authentication for each request. Here's a simplified TypeScript example to help you implement this authentication method:
In this example, we first define a getClient
function that takes a url
and a didAuthFunction
. The didAuthFunction
should be an asynchronous function that returns a signed challenge as a string.
The getChallenges
function fetches a list of challenges from the API. The getAuthHeaders
function generates an Authorization header using the didAuthFunction
and a challenge. This header can then be used in your API calls.
The system uses several middleware layers for authentication and authorization:
openRoute
: Base middleware that allows public access
didRoute
: Requires a valid DID in the request
didAndChallengeRoute
: Requires a valid DID and challenge
profileRoute
: Requires a valid DID, challenge, and existing profile
scopedRoute
: Requires specific permission scopes
Each API endpoint requires specific scopes for authorization:
profiles:read
Read profile information
getProfile
, getOtherProfile
profiles:write
Create or update profiles
createProfile
, updateProfile
profiles:delete
Delete profiles
deleteProfile
connections:read
View connections
paginatedConnections
connections:write
Manage connections
connectWith
, blockProfile
signingAuthorities:read
View signing authorities
signingAuthorities
signingAuthorities:write
Manage signing authorities
registerSigningAuthority
The authorization system also supports wildcard scopes like *:read
(read access to all resources) and *:*
(full access).