I use the [Metadata API and the Apex wrapper][1]Metadata API and the Apex wrapper to create an AuthProvider
and NamedCredential
after the installation of my managed package app.
MetadataService.NamedCredential cred = new MetadataService.NamedCredential();
cred.fullName = 'MyCred';
cred.label = 'MyCred';
cred.allowMergeFieldsInBody = false;
cred.allowMergeFieldsInHeader = true;
cred.authProvider = 'MyKeycloak';
cred.generateAuthorizationHeader = true;
cred.oauthScope = 'api refresh_token';
cred.principalType = 'NamedUser';
cred.protocol = 'Oauth';
cred.endpoint = apiEndpoint.trim();
The problem is the Authorization is still in Pending
status as a user seems to manually Edit and Save the Named Credential to trigger it.
Is there a way I can trigger that by my code when I insert the NamedCredential? [1]: https://github.com/financialforcedev/apex-mdapi