About Me

My photo
PLANO, Texas, United States

Monday, December 27, 2021

Delegated Authentication

  • As the name suggests, in delegated authentication, authentication is delegated to an external party. With delegated authentication, Salesforce has no control over the passwords used to log in to your org. Instead, the external authentication method controls user passwords and associated policies.

  • With Delegated Authentication, the user logs in through the normal Salesforce login page, but Salesforce checks with a third-party server for the password. In this case, the user literally has no Salesforce password and cannot log in without the authentication server's permission.

  • Example-For example, your company uses an LDAP server for its employees. You want to use the LDAP server to authenticate users into Salesforce. You also want to use permissions on the user profile to determine whether users authenticate with LDAP or Salesforce. Specifically, you want users with standard profiles to log in with a password managed by the LDAP server, while system administrator profiles use a Salesforce password. So, you integrate your org with your LDAP server by wrapping the LDAP server in a SOAP-based web service. You create permissions so that only users with standard profiles use delegated authentication. Now, users with standard profiles enter a Salesforce username and the LDAP server handles their password. Users with system administrator profiles enter their Salesforce username and password.

Delegated Authentication’s Flow 

  1. When a user tries to log in (either online or using the API), Salesforce tries to validate the username and checks the user’s permissions and access settings.

  2. If the “Is Single Sign-On Enabled” user permission is enabled, Salesforce calls the SOAP-based SSO web service to validate the username and password.

  3. The web service call passes the username, password, and source IP to your SSO web service implementation, which Salesforce servers then access. The source IP is the address where the login request originated.

  4. Your SSO web service implementation validates the passed information and returns either true or false.

  5. When the response is true, the login process continues and the user is logged in to your org. When false, the user gets an error message that the username and password combination is invalid.


How to configure Delegated Authentication?

To configure Salesforce for delegated authentication: Follow the instructions in the Salesforce documentation to enable delegated authentication single sign-on for your organization.

  1. After delegated authentication has been enabled at Salesforce, complete the following configuration steps:

    1. Enable delegated authentication for your org-

      1. From Setup, in the Quick Find box, enter Single Sign-On Settings, then select Single Sign-On Settings.

      2. Select Disable login with Salesforce credentials

    2. Build your web service.

    3. Specify your delegated authentication gateway URL:

Click Your Name > Setup > Security Controls > Single Sign-On Settings > Edit.

Enter the URL for the Delegated Gateway URL

  1. Enable permissions-Enable the Is Single Sign-On Enabled permission for all the users you want to use delegated authentication

Some Use Case

Restricting certain users to log in only using federated SSO and not by regular salesforce users and passwords using login.salesforce.com or my domain url. This can be achieved by using delegated authentication. You can refer to below article  https://www.youtube.com/watch?v=ivYsRZUYlXw 

Consideration 

  • Orgs implementation of Web service must be accessible from Salesforce servers. Deploy the web service on a server in DMZ.

  • If Salesforce and your system can’t connect, or if the request takes longer than 10 seconds to process, the login attempt fails. The user gets an error message indicating that the corporate authentication service is down.

  • Namespaces, element names, and capitalization must be exact in SOAP requests.

  • Wherever possible, generate your server stub from the WSDL file to ensure accuracy.

  • Make web service available by TLS. A certificate from a trusted provider, such as Verisign or Thawte, is required

  • The IP address that originated the login request is sourceIp. Use this information to restrict access based on the user’s location.

  • Ensure that Salesforce IP Addresses are whitelisted on the corporate firewall.

  • Map org’s internal usernames to your Salesforce usernames.

  • Do not enable SSO for admins to ensure that they are not locked out when the web service is down.

  • Delegated authentication is managed at the permission level and not at the org level

  • Password reset is disabled for delegated authentication because Salesforce no longer manages user passwords. Users who try to reset their passwords in Salesforce are directed to their Salesforce admin

Troubleshoot Delegated Authentication Login Errors

  • Admins with the Modify All Data permission can view the 21 most recent login errors for your Salesforce org. From Setup, in the Quick Find box, enter Delegated Authentication Error History, then select Delegated Authentication Error History. For each failed login, you can view the user's username, login time, and the error. 

Sunday, December 26, 2021

oAuth 2.0

OAuth 2.0 is a framework used to allow secure data sharing between applications. The user works in one app but sees the data from another.  For example, you’re logged in to your Salesforce mobile app and see your data from your Salesforce org. Behind the scenes, the apps perform a kind of handshake and then ask the user to authorize this data sharing. When developers want to integrate their app with Salesforce, they use OAuth APIs. Here are a couple of examples.

  • A mobile app that pulls contacts from a Salesforce org uses OAuth.

  • A Salesforce org that gets contacts from another service also uses OAuth.

  • Workbench uses oAuth 2.0 protocol for connecting with salesforce.

Connected App

  • Connected app framework controls external applications to salesforce

  • Connected app uses standard protocols such as SAML,oAuth, OpenConnect

  • There are four main use cases for which your org can implement connected apps. 

    • Access Data with API Integration- You can use a connected app to integrate external applications with the Salesforce API, such as a web-based app that pulls in order status data from your Salesforce org. 

    • Integrate Service Providers with Your Salesforce Org- You can also use connected apps to integrate service providers with your Salesforce org, 

    • Manage Access to Third-Party Apps- To set security policies to control what data a third-party app can access from your org. 

    • Provide Authorization for External API Gateways- You can configure a connected app to provide authorization for external API gateways, such as API gateways hosted on MuleSoft’s Anypoint Platform.

Connected app owner vs connected app consumer

As a connected app owner, your org built the app. You can edit the app’s characteristics and manage its access policies. For example, you decide the type of information (such as a client secret) that the connected app must provide to gain access to data in your org. So how can you easily tell whether your org owns a connected app? The best way is to locate the connected app in the App Manager, click the dropdown arrow next to it, and see which options are provided.

As a connected app consumer, your org installed the app from the AppExchange, as a managed package from another org or a third-party vendor’s website, or as metadata without packaging. You can edit only the app’s access policies, such as who can use the app and whether the app can access data from a remote location.

Tokens

Salesforce uses OAuth protocol to allow users of applications to securely access data without having to reveal the username and password credentials. Now the question is how it works without a password? The answer is Token. With the help of Token, it connects to other applications. There are the following types of tokens:

  1. Authorization code- 

    1. The authorization server creates an authorization code, which is a short-lived token and passes it to the client after successful authentication. Only used in OAuth 2.0 with the web-server flow, the authorization code is a token that represents the access granted by the end-user. The authorization code is used to obtain an access token and a refresh token. It expires after 15 minutes.

    2. The client sends the authorization code to the authorization server to obtain an access token and, optionally, a refresh token

  2. Access Token - 

    1. Instead of using the user’s Salesforce credentials, a consumer (connected app) can use an access token to gain access to protected resources on behalf of the user.

    2. After a client is authorized, Salesforce sends the client an access token. The client passes the access token to the resource server to request access to protected resources. The resource server validates the access token and additional permissions in the form of scopes before granting access to the client.

    3. The access token has a longer lifetime than the authorization code, usually minutes or hours. When an access token expires, attempts to use it fail, and the client must obtain a new access token by using a refresh token or reinitiating the authorization flow.

  3. Refresh Token- 

  1. Like a password, a client can repeatedly use a refresh token to gain access to the resource server. When a refresh token expires or a user revokes it outside of the client, the client requests a new access token, typically by implementing the authorization flow from the start.

  2. A refresh token can have an indefinite lifetime, persisting for an admin-configured interval or until explicitly revoked. The client can store a refresh token and use it to obtain new access tokens. For security, the client must protect a refresh token against unauthorized access.

  3. The OAuth 2.0 user-agent and the OAuth 2.0 web server flows can request refresh tokens if the refresh_token or offline_access scope is included in the request.

4. Id Token - Users for OpenId connect.

oAuth Scope

  • Scope provides selective enabling of access to a user’s account based on required functionality

  • In Salesforce, scopes control the types of resources available to an application. Some of the scopes are:

    • Api - Allows access to the current, logged-in user’s account using APIs, such as REST API and Bulk API 2.0. This scope also includes chatter_api, which allows access to Connect REST API resources.

    • Chatter_api

    • Full - Allows access to all data accessible by the logged-in user, and encompasses all other scopes. NOTE full doesn’t return a refresh token. You must explicitly request the refresh_token scope to get a refresh token.

    • Id- Allows access to the identity URL service. You can request a profile, email, address, or phone individually to get the same result as using id because they’re synonymous.

    • Refresh_token-Allows a refresh token to be returned when the requesting client is eligible to receive one. With a refresh token, the app can interact with the user’s data while the user is offline. This token is synonymous with requesting offline_access.

    • web- This scope allows the app to use the access token on the web, and allows access to customer-created Visualforce pages.

Manage Access to a Connected App

With the help if OAuth Policies, you can manage below two items:

  1. Which Users Can Access the Connected App - Configure the Permitted Users policy. The Permitted Users policy defines whether users are pre-authorized to run the connected app. The Admin approved users pre-authorized option allows only users with the associated profile to access the app without first authorizing it. The All Users may self-authorize option enables anyone in the org to authorize the app after successfully signing in

  2. Where Users Can Access the Connected App From-Under OAuth policies, click the IP Relaxation dropdown. These are the options you can choose from:

    1. Enforce IP restrictions—This option enforces the IP restrictions configured for the org, such as the IP ranges assigned to a user profile.

    2. Enforce IP restrictions, but relax for refresh tokens—Like the Enforce IP restrictions option, this option enforces the IP restrictions configured for the org, such as the IP ranges assigned to a user profile. However, this option bypasses these restrictions when the connected app uses refresh tokens to get access tokens. 

    3. Relax IP restrictions for activated devices—This option allows a user running the app to bypass the org’s IP restrictions when either of these conditions is true.

      1. The app has a list of allowed IP ranges and is using the web server OAuth authorization flow. Only requests coming from these IPs are allowed.

      2. The app doesn’t have a list of allowed IP ranges. But it uses the web server authentication flow, and the user successfully completes identity verification if accessing Salesforce from a new browser or device.

    4. Relax IP restrictions—This option allows a user to run this app without org IP restrictions.Although this option would allow Help Desk users to run the Customer Order Status App from a customer’s site, the user wouldn’t have to verify their identity to Salesforce. You want to maintain the security that authentication provides, so you don’t want to use this option for the connected app.


oAuth Flow

An oAuth authentication flow defines a series of steps used to coordinate the authentication process between your application and salesforce.

Salesforce provides you with a wealth of different flows - each serving a different purpose. For almost all flows, a connected app must be created in Salesforce first before a connection can be established.

  1. User-Agent Flow (Mobile/Desktop App Integration)

  2. Web Server Authentication Flow (Web Application Integration)

  3. JWT Bearer Token Flow (Server to Server Integration)

  4. SAML Bearer Assertion Flow

  5. Refresh Token Flow

  6. Username and Password Flow 

  7. Device Authentication Flow (IoT Integration)

  8. Asset Token Flow


User-Agent Flow (Mobile App Integration)

  • It is used for mobile or desktop applications, for example, Dataloader, Salesforce1, or Mobile SDK.

  • It allows a user to authenticate to a partner application using their Salesforce login credentials. Once logged, a user must approve that the partner application can access certain elements in Salesforce (you define those in your connected app). 

  • This flow assumes by default that partner applications cannot be trusted, hence you should use this flow when your partner application cannot protect the client secret issued by Salesforce's connected app. 

  • This, for example, is the case in mobile or desktop applications that you would like to connect to Salesforce where the source code of the application is accessible by the user and the client secret could be exposed easily. The benefit of this flow is that Salesforce issues a refresh token, meaning that even when your access token expires, you are able to obtain a new one by executing the refresh token flow. This will save the user from having to log in to Salesforce again.



Web Server Authentication Flow (Authorization code grant type)

  • This is used for Web App Integration. If you are integrating an external web service (the Customer Order Status website) with the Salesforce API, you can use Web Server authentication flow if:

    • Used for apps that are hosted on a secure server.

    • If your application is capable of protecting the client's secret

  • For example, you’ve recently developed a website that allows secure access to customer order status. The order status data is securely stored in your Salesforce CRM platform. To authorize Help Desk users to view a customer’s order status, you develop an Order Status app and configure it as a connected app with the web server flow.

  • This flow still requires the user to actively log in to Salesforce and to approve access hence I would not use this flow when connecting API-only applications (such as an ESB or ETL tool that connects to Salesforce). 

  • This flow also issues you refresh token and the user does not need to approve the access again.

JWT Bearer Token Flow (Server-to-Server Integration)

  • In some cases, you need to authorize servers without interactively logging in each time the servers need to exchange information.If you want to connect an API-only application that essentially does not provide a UI that would allow a user to approve the external application, it would be strongly recommended the OAuth 2.0 JWT Bearer Token Flow.

  • To provide authorization for server-to-server integration, you can use the OAuth 2.0 JSON Web Token (JWT) bearer flow. This flow requires prior approval of the client app.

  • The OAuth 2.0 JWT Bearer Token Flow requires you to upload a certificate to your connected app that will be used to validate the JWT token. As the name of the flow already states, you will need to create a JWT token. This is basically a JSON file consisting of a header and claims object, where the header contains the signature algorithm and the object of the claim contains specific information such as the username and consumer key. At a high level, you will then sign the JSON object with the private key of your certificate and send the JWT to Salesforce to obtain an access token. This flow does not issue a refresh token and the server must create a new JWT token once the access token expires.

SAML Bearer Assertion Flow

  • If your organization uses a central access control such as an active directory or LDAP store, it is likely that you would SSO to authenticate to your application. In this scenario, you may also want to use the SAML assertion from your SSO flow to obtain an access token to Salesforce. 

  • This flow basically takes the SAML assertion (an XML token issued by your IdP) and applies a digital signature to it using a certificate. The connected app configuration in Salesforce is similar to the one done in the JWT Bearer Token Flow wherein a certificate is uploaded which is used to sign the SAML assertion.

Refresh Token Flow

As part of the web server and user-agent flows, a connected app can use a refresh token to request a new access token after the current access token expires. This flow is particularly helpful when you don’t want user intervention after an app is authorized.

Username-Password Flow-

  • The OAuth 2.0 Username and Password Flow quite simply issues an access token in exchange for a username and password. This is not recommended using this flow unless there is absolutely no other way because you are sending the password unencrypted to Salesforce.

IoT Integration (OAuth 2.0 Device Flow)

  • To integrate devices with limited input or display capabilities, such as Smart TVs, you can configure connected apps with the OAuth 2.0 device flow.

  • With the device flow, end users can authorize connected apps to access Salesforce data using a web-based browser.

  • For example, a customer uses your bluetooth device to control their house lights while they are away for the evening. You can create a connected app for the bluetooth device to enable this flow.

Reference

  1. Web Server flow

  2. Connected App



Saturday, December 25, 2021

Custom Login Flow

 Custom Login Flow

  • Custom login flow allows you to invoke the business process during login.

  • It is profile-based association means you can decide which flow should run for which profile

  • It supports username/Password, SAML SSO, Social SSO Logins.

  • It is applicable in salesforce, community and Salesforce1

  • Custom Login Flows connects to the existing custom 2FA system for use in Salesforce.

  • To invoke a login flow, the user must first be authenticated. Login flows don’t replace the existing Salesforce authentication process. They integrate new steps or ask the user for information.

Login Flow Use Cases

  • Custom Login Experience-Enhance or customize the login experience by adding a logo or login message.

  • Collect and update user data, such as an email address, phone number, or mailing address.

  • Accept Terms of Services-Interact with users, and ask them to perform an action. For instance, you can ask them to complete a survey or accept terms of service.

  • Geo-Fencing-Connect to a Salesforce Customer Identity service or geo-fencing service, and collect or verify user information.

  • Custom Multi-Factor Authentication-Enforce strong authentication, like implementing a multi-factor authentication (MFA) method using hardware, biometric, or another authentication technique.

  • Identity Confirmation-Run a confirmation process. For example, have a user define a secret question, and validate the answer during login.

  • Create more granular policies like setting up a policy that sends a notification every time a user logs in during non-standard working hours.

How does it work?

Custom Login flow works on below ways:

  1. To create a flow, use either Flow Builder or Visualforce. Flow Builder is a point-and-click tool that you can use to design a simple flow that users execute when logging in. Use Visualforce to have complete control over how the login page looks and behaves

  2. Set Up a Login Flow and Connect to Profiles- Once you have Flow or VF, you can align that with profile as below:

    1. From Setup, in the Quick Find box, enter Login, and select Login Flows.

    2. Click New.

    3. On the Login Flow Edit page, enter a name for the login flow.


Please refer below session for getting more details:

https://www.youtube.com/watch?v=gYes8OLAc-k 


Multi-Factor Authentication

  • When a system asks for more than one way for authentication, it's called Multi-Factor Authentication. Multi-factor authentication (MFA) is a secure authentication method that requires users to prove their identity by supplying two or more pieces of evidence (or factors) when they log in. 

  • One factor is something the user knows, such as their username and password. Other factors include something the user has, such as an authenticator app or security key. By tying user access to multiple types of factors, MFA makes it much harder for common threats like phishing attacks and account takeovers to succeed. Note: MFA was formerly called two-factor authentication or 2FA.

How to enable MFA?

Enabling MFA is too simple and you can follow the below steps for that. You can enable “Manage Multi-Factor Authentication in User Interface” on your profile or permission set under system permission.

  1. Create a permission set called “MFA Permission Set”. 

  2. Go to the “FMA Permission set” and go to system permission and click “Manage Multi-Factor Authentication in User Interface”.

  3. Assign the permission set to the user.

What will happen when a user will log in to salesforce who has MFA enabled?

When a user login to salesforce org, system will prompt to have verification code, there are different verification methods as below:

  1. Salesforce Authentication app

  2. 3rd Party authentication app like google authentication, Microsoft authentication app

  3. Security Key like Yubico's yubikey, Goggle's Titan Security Key


You can refer below link for more understanding:

https://salesforce.vidyard.com/watch/O3rQLAtVX0Z4lLjdOvVFYQ