in pkg/internal/token/clientcertcredentialwithpop.go [24:66]
func newClientCertificateCredentialWithPoP(opts *Options) (CredentialProvider, error) {
if opts.ClientID == "" {
return nil, fmt.Errorf("client ID cannot be empty")
}
if opts.TenantID == "" {
return nil, fmt.Errorf("tenant ID cannot be empty")
}
if opts.ClientCert == "" {
return nil, fmt.Errorf("client certificate cannot be empty")
}
popClaimsMap, err := parsePoPClaims(opts.PoPTokenClaims)
if err != nil {
return nil, fmt.Errorf("unable to parse PoP claims: %w", err)
}
if len(popClaimsMap) == 0 {
return nil, fmt.Errorf("number of pop claims is invalid: %d", len(popClaimsMap))
}
// Get the certificate and private key from cert file
cert, rsaPrivateKey, err := readCertificate(opts.ClientCert, opts.ClientCertPassword)
if err != nil {
return nil, fmt.Errorf("failed to read certificate: %w", err)
}
cred, err := confidential.NewCredFromCert([]*x509.Certificate{cert}, rsaPrivateKey)
if err != nil {
return nil, fmt.Errorf("unable to create credential from certificate: %w", err)
}
msalOpts := &pop.MsalClientOptions{
Authority: opts.GetCloudConfiguration().ActiveDirectoryAuthorityHost,
ClientID: opts.ClientID,
TenantID: opts.TenantID,
DisableInstanceDiscovery: opts.DisableInstanceDiscovery,
}
if opts.httpClient != nil {
msalOpts.Options.Transport = opts.httpClient
}
return &ClientCertificateCredentialWithPoP{
popClaims: popClaimsMap,
cred: cred,
options: msalOpts,
}, nil
}