Federated Managed Identity (FMI) allows Azure services to use federated credentials for authentication via an assertion callback. To use FMI, you must use the special client ID urn:microsoft:identity:fmi when initializing your confidential client. The process involves creating a credential using confidential.NewCredFromAssertionCallback, which takes a function that dynamically retrieves the FMI token (typically from a Resource Management API service) whenever a new assertion is required.
func main() {
ctx := context.Background()
// Create FMI credential using assertion callback
fmiCred := confidential.NewCredFromAssertionCallback(
func(ctx context.Context, aro confidential.AssertionRequestOptions) (string, error) {
return GetFMICredentialFromRMA(ctx)
},
)
// Create confidential client with FMI client ID
app, err := confidential.New(
"https://login.microsoftonline.com/tenant-id",
"urn:microsoft:identity:fmi", // Special FMI client ID
fmiCred,
confidential.WithCache(cacheAccessor),
)
if err != nil {
panic(err)
}
// Acquire token using FMI
result, err := app.AcquireTokenByCredential(
ctx,
[]string{"your-resource/.default"},
confidential.WithFMIPath("YourFmiPath/CredentialPath"),
)
if err != nil {
panic(err)
}
// Use the access token
accessToken := result.AccessToken
}