Self provides a secure authentication workflow that allows users to authenticate themselves using their digital identity. This workflow is designed to be scalable and can be used in a variety of scenarios, such as:
Once we have the user's address (userAddress), we can request specific credentials from them. In this example, we're requesting a liveness credential. For more details on credential presentation requests, check out the Credential Presentation guide.
After receiving the credential presentation response, we need to validate the credentials. This involves checking the presentation's validity, the credential's validity, and extracting the claims. For more information on credential validation, see the Credential Validation guide.
for_,credential:=rangepresentation.Credentials(){ifcredential.CredentialType()[0]=="VerifiableCredential"&&credential.CredentialType()[1]=="LivenessCredential"{err=credential.Validate()iferr!=nil{log.Printf("WARN: failed to validate credential - error: %v",err)continue}ifcredential.ValidFrom().After(time.Now()){log.Println("WARN: credential is intended to be used in the future")continue}claims,err:=credential.CredentialSubjectClaims()iferr!=nil{log.Printf("WARN: failed to parse credential claims - error: %v",err)continue}fork,v:=rangeclaims{log.Printf("INFO: credential value - credentialType: %s, field: %s, value: %v",credential.CredentialType(),k,v)}}}
This example demonstrates how to build a simple secure authentication workflow with Self. We've seen how to use Self Discovery to find the DIDs of the users we want to authenticate, how to send a credential presentation request for the appropriate credentials, and how to validate the presentations and credentials.
For the complete example, including error handling and additional details, please refer to our GitHub repository.
By leveraging these Self features, you can create a robust, secure, and privacy-preserving authentication system for your applications.