The class runs on behalf of the current user of the connected app. This user must have permission to use the connected app for the plugin to work.
The following example gives the user permission to use the connected app if a specified quota is met, and returns the user’s permission set assignments.
global class ConnectedAppPluginExample extends Auth.ConnectedAppPlugin{ //Authorize the app if the user has achieved quota tracked in a custom field global override boolean authorize(Id userId, Id connectedAppId, boolean isAdminApproved) { User u = [select id, HasAchievedQuota__c from User where id =: userId].get(0); return u.HasAchievedQuota__c; } //Call a flow during refresh global override void refresh(Id userId, Id connectedAppId) { { Map<String, Object> inputVariables = new Map<String, Object>(); inputVariables.put('userId', userId); inputVariables.put('connectedAppId', connectedAppId); Flow.Interview.MyCustomFlow interview = new Flow.Interview.MyCustomFlow(inputVariables); interview.start(); } catch ( Exception e ) { System.debug('FLOW Exception:' + e); } } //Return a user’s permission set assignments global override Map<String,String> customAttributes(Id userId, Map<String,String> formulaDefinedAttributes) { List<PermissionSetAssignment> psas = [SELECT id, PermissionSet.Name FROM PermissionSetAssignment WHERE PermissionSet.IsOwnedByProfile = false AND (AssigneeId = :userId)]; String permsets = '['; for (PermissionSetAssignment psa :psas){ permsets += psa.PermissionSet.Name + ';'; } permsets += ']'; formulaDefinedAttributes.put('PermissionSets', permsets); return formulaDefinedAttributes; } }
The following are methods for ConnectedAppPlugin.
public Boolean authorize(Id userId, Id connectedAppId, Boolean isAdminApproved)
Type: Boolean
If the connected app requires admin approval, a returned value of true indicates that the current user is approved.
If the connected app is set for users to self-authorize, this call isn’t necessary.
public Map<String,String> customAttributes(Id userId, Map<String,String> formulaDefinedAttributes)