Skip to main content
Commonmark migration
Source Link

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

I use the [Metadata API and the Apex wrapper][1] 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

I use the 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?

edited title
Link
identigral
  • 7.8k
  • 34
  • 33
  • 45

How to trigger Authentification of Named Credential created Initiate an oAuth flow via Apexan Auth Provider

deleted 908 characters in body
Source Link
Robert Sösemann
  • 38.2k
  • 29
  • 173
  • 508

I use the [Metadata API and the Apex wrapper][1] to create an AuthProvider and NamedCredential after the installation of my managed package app.

createSObject('<urn1:type>AuthProvider</urn1:type>' +
    '<urn1:DeveloperName>MyKeycloak</urn1:DeveloperName>' +
    '<urn1:FriendlyName>My Auth Provider</urn1:FriendlyName>' +
    '<urn1:ProviderType>OpenIdConnect</urn1:ProviderType>' +
    '<urn1:OptionsSendAccessTokenInHeader>true</urn1:OptionsSendAccessTokenInHeader>' +
    '<urn1:OptionsSendClientCredentialsInHeader>false</urn1:OptionsSendClientCredentialsInHeader>' +
    '<urn1:DefaultScopes>api refresh_token</urn1:DefaultScopes>' +
    '<urn1:ConsumerKey>' + authKey + '</urn1:ConsumerKey>' +
    '<urn1:ConsumerSecret>' + authSecret + '</urn1:ConsumerSecret>' +
    '<urn1:AuthorizeUrl>' + authEndpoint + '/auth</urn1:AuthorizeUrl>' +
    '<urn1:TokenUrl>' + authEndpoint + '/token</urn1:TokenUrl>' +
    '<urn1:UserInfoUrl>' + authEndpoint + '/userinfo</urn1:UserInfoUrl>'
);

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

I use the [Metadata API and the Apex wrapper][1] to create an AuthProvider and NamedCredential after the installation of my managed package app.

createSObject('<urn1:type>AuthProvider</urn1:type>' +
    '<urn1:DeveloperName>MyKeycloak</urn1:DeveloperName>' +
    '<urn1:FriendlyName>My Auth Provider</urn1:FriendlyName>' +
    '<urn1:ProviderType>OpenIdConnect</urn1:ProviderType>' +
    '<urn1:OptionsSendAccessTokenInHeader>true</urn1:OptionsSendAccessTokenInHeader>' +
    '<urn1:OptionsSendClientCredentialsInHeader>false</urn1:OptionsSendClientCredentialsInHeader>' +
    '<urn1:DefaultScopes>api refresh_token</urn1:DefaultScopes>' +
    '<urn1:ConsumerKey>' + authKey + '</urn1:ConsumerKey>' +
    '<urn1:ConsumerSecret>' + authSecret + '</urn1:ConsumerSecret>' +
    '<urn1:AuthorizeUrl>' + authEndpoint + '/auth</urn1:AuthorizeUrl>' +
    '<urn1:TokenUrl>' + authEndpoint + '/token</urn1:TokenUrl>' +
    '<urn1:UserInfoUrl>' + authEndpoint + '/userinfo</urn1:UserInfoUrl>'
);

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

I use the [Metadata API and the Apex wrapper][1] 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

Added creation of External Auth Provider
Source Link
Robert Sösemann
  • 38.2k
  • 29
  • 173
  • 508
Loading
Became Hot Network Question
Tweeted twitter.com/StackSalesforce/status/1148653320824905729
Source Link
Robert Sösemann
  • 38.2k
  • 29
  • 173
  • 508
Loading