Newer Version Available
ConnectedAppPlugin Class
Namespace
Usage
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.
Example
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.
1global class ConnectedAppPluginExample extends Auth.ConnectedAppPlugin{
2
3 //Authorize the app if the user has achieved quota tracked in a custom field
4 global override boolean authorize(Id userId, Id connectedAppId, boolean isAdminApproved) {
5
6 User u = [select id, HasAchievedQuota__c from User where id =: userId].get(0);
7 return u.HasAchievedQuota__c;
8
9 }
10
11 //Call a flow during refresh
12 global override void refresh(Id userId, Id connectedAppId) {
13
14 {
15 Map<String, Object> inputVariables = new Map<String, Object>();
16 inputVariables.put('userId', userId);
17 inputVariables.put('connectedAppId', connectedAppId);
18 Flow.Interview.MyCustomFlow interview = new Flow.Interview.MyCustomFlow(inputVariables);
19 interview.start();
20 } catch ( Exception e ) {
21 System.debug('FLOW Exception:' + e);
22 }
23
24 }
25
26 //Return a user’s permission set assignments
27 global override Map<String,String> customAttributes(Id userId, Map<String,String> formulaDefinedAttributes) {
28
29 List<PermissionSetAssignment> psas = [SELECT id, PermissionSet.Name FROM PermissionSetAssignment WHERE PermissionSet.IsOwnedByProfile = false AND (AssigneeId = :userId)];
30 String permsets = '[';
31 for (PermissionSetAssignment psa :psas){
32 permsets += psa.PermissionSet.Name + ';';
33 }
34 permsets += ']';
35 formulaDefinedAttributes.put('PermissionSets', permsets);
36 return formulaDefinedAttributes;
37
38 }
39
40}ConnectedAppPlugin Methods
The following are methods for ConnectedAppPlugin.
authorize(userId, connectedAppId, isAdminApproved)
Signature
public Boolean authorize(Id userId, Id connectedAppId, Boolean isAdminApproved)
Parameters
Return Value
Type: Boolean
If the connected app requires admin approval, a returned value of true indicates that the current user is approved.
Usage
If the connected app is set for users to self-authorize, this call isn’t necessary.
customAttributes(userId, formulaDefinedAttributes)
Signature
public Map<String,String> customAttributes(Id userId, Map<String,String> formulaDefinedAttributes)
Parameters
- userId
- Type: Id
- The 15-character ID for the user associated with the attributes.
- formulaDefinedAttributes
- Type: Map<String,String>
- A map of the current set of attributes from the UserInfo endpoint (OAuth) or from a SAML assertion. For more information, see The UserInfo Endpoint in the online help.