Skip to content

Conversation

@RojaEnnam
Copy link

@RojaEnnam RojaEnnam commented May 14, 2025

Description

Add SigningCredential loading to DefaultCredentialsLoader

Fixes #{3359}

@jmprieur
Copy link
Collaborator

Thanks @RojaEnnam
It's a good start. You might want to create a new interface

return new X509SigningCredentials(credentialDescription.Certificate, credentialDescription.Algorithm);
}

return null;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning null if Certificate is not loaded because a null certificate is a valid state. Open to suggestions.

{
await LoadCredentialsIfNeededAsync(credentialDescription, parameters);

if (credentialDescription.Certificate != null)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shows creating the SigningCredentials only from the certificate. I've included the proposal to add support for loading SymmetricSecurityKey in this PR.

StoreWithDistinguishedName = 5,

// New values
SymmetricKeyFromKeyVault = 6,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would not be 6, which is already used.
Is it a common scenario to get symmetric keys from KeyVault? or would they rather come from somewhere else? (like the metadata document). Do we have customer requests for symmetric keys?

Would it be a thing to expose the symmetric key as base64encoded?

In that case should the Algorithm be used? or is it already in the key?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will update the right number in the implementation, this is created by CLINE and it knew only the IdWeb files.

For ServerNoncePolicy the credentials can also be Symmetric, today we have this supported in SAL. I am not aware of other places the key can come from, but today in SAL they are being expected to come from either KeyVault or base64encoded string. Algorithm is still used while creating the SigningCredentials from the key see here

<MicrosoftGraphVersion>4.36.0</MicrosoftGraphVersion>
<MicrosoftGraphBetaVersion>4.57.0-preview</MicrosoftGraphBetaVersion>
<MicrosoftIdentityAbstractionsVersion>9.0.0</MicrosoftIdentityAbstractionsVersion>
<MicrosoftIdentityAbstractionsVersion>9.1.0</MicrosoftIdentityAbstractionsVersion>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not published, @RojaEnnam FYI

<packageSources>
<clear />
<add key="NuGet" value="https://api.nuget.org/v3/index.json" />
<add key="Local" value="C:\repos\Builds\abstractions" />
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No longer needed


/// <inheritdoc/>
public async Task<SigningCredentials?> LoadSigningCredentialsAsync(
CredentialDescription credentialDescription,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: spacing (add a tab to the params)

Following the same pattern as CertificateDescription:

```csharp
public class SymmetricKeyDescription : CredentialDescription
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CredentialDescription class already has the responsibility of managing different types of credentials - see the CredentialType property - it can handle Certificates, Signed Assertions (i.e. JWT tokens with a special audience to denote they are actually credentials), client secrets and decrypt keys.

Have you considered just extending CredentialDescription instead of creating a new class? What are the pros / cons?

{
// Convert secret value to bytes and create SymmetricSecurityKey
var keyBytes = Convert.FromBase64String(secret.Value.Value);
description.CachedValue = new SymmetricSecurityKey(keyBytes);
Copy link
Member

@bgavrilMS bgavrilMS May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fact that CachedValue is an object is requires users to cast to the right object (string, X509Certificate2 etc.).

At least for certificates, a Certificate property also exists to avoid a cast. I suggest you do the same for symmetric keys?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(read my comments below about extending CredentialDescription first)

};
}

public async Task<SigningCredentials?> LoadSigningCredentialsAsync(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if a simpler design would be to rely on the existing object model, i.e. ICredentialsLoader and to treat the SymmetricSecurityKey as another type of credential - see CredentialType enum (alongside DecryptKeys, which is also not used by MSAL).

Apart from simpelr object model, this would avoid mixing the concept of SigningCredentials in Id.Web. I believe SigningCredentials + X509 has some perf implications (i.e. loading it often is expensive, caching needs to be done).

/// <param name="credentialDescription">Credential description.</param>
/// <param name="parameters">Optional parameters for loading credentials.</param>
/// <returns>SigningCredentials if successful, null otherwise.</returns>
Task<SigningCredentials?> LoadSigningCredentialsAsync(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this is needed if CredentialDescription can alraedy return an X509Certificate2 and potentially a SymmetricKey . It becomes just a convenience method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants