Skip to content

Commit

Permalink
Add Salesforce provider
Browse files Browse the repository at this point in the history
  • Loading branch information
engram-design committed Mar 26, 2024
1 parent ca7b082 commit d03d824
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 1 deletion.
32 changes: 31 additions & 1 deletion docs/providers/all-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Social Login integrates with the following providers:
- [Pinterest](https://pinterest.com)
- [Pipedrive](https://pipedrive.com)
- [Reddit](https://reddit.com)
- [Salesforce](https://salesforce.com)
- [Shopify](https://shopify.com)
- [Slack](https://slack.com)
- [Snapchat](https://snapchat.com)
Expand Down Expand Up @@ -563,10 +564,39 @@ Follow the below steps to connect to the Reddit API.
### Connect to the Reddit API
1. Go to <a href="https://www.reddit.com/prefs/apps" target="_blank">Reddit</a> and login to your account.
1. Click the **are you a developer? create an app...** button.
1. In the **ARedirect URI** field, enter the value from the **Redirect URI** field in Social Login.
1. In the **Redirect URI** field, enter the value from the **Redirect URI** field in Social Login.
1. Copy the **Client ID** from Reddit and paste in the **Client ID** field in Social Login.
1. Copy the **Client Secret** from Reddit and paste in the **Client Secret** field in Social Login.

## Salesforce
Follow the below steps to connect to the Salesforce API.

### Connect to the Salesforce API
1. Go to <a href="https://www.salesforce.com/" target="_blank">Salesforce</a> and login to your account.
1. In the main menu, on the top-right, click the **Settings** icon and select **Setup**.
1. In the left-hand sidebar, click on **Apps****App Manager**.
1. Click the **New Connected App** button.
1. Fill out all required fields.
1. In the **API (Enable OAuth Settings)** section, tick the **Enable OAuth Settings** checkbox.
- In the **Callback URL** field, enter the value from the **Redirect URI** field in Social Login.
- In the **Selected OAuth Scopes** field, select the following permissions from the list and click **Add** arrow button:
- **Access and manage your data (api)**
- **Allow access to your unique identifier (openid)**.
- **Perform requests on your behalf at any time (refresh_token, offline_access)**.
- These may also appear named as the following:
- **Manage user data via APIs (api)**
- **Access unique user identifiers (openid)**
- **Perform requests at any time (refresh_token, offline_access)**
1. Click the **Save** button.
1. Copy the **Consumer Key** from Salesforce and paste in the **Client ID** field in Social Login.
1. Copy the **Consumer Secret** from Salesforce and paste in the **Client Secret** field in Social Login.
1. Click on the **Manage** button.
1. Click on the **Edit Policies** button.
1. In the **OAuth policies** section:
- In the **Permitted Users** field, select **All users may self-authorize**.
- In the **IP Relaxation** field, select **Relax IP restrictions**.
1. Click the **Save** button.


## Shopify
Follow the below steps to connect to the Shopify API.
Expand Down
73 changes: 73 additions & 0 deletions src/providers/Salesforce.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
namespace verbb\sociallogin\providers;

use verbb\sociallogin\base\OAuthProvider;

use craft\helpers\App;

use verbb\auth\providers\Salesforce as SalesforceProvider;

class Salesforce extends OAuthProvider
{
// Static Methods
// =========================================================================

public static function getOAuthProviderClass(): string
{
return SalesforceProvider::class;
}


// Properties
// =========================================================================

public static string $handle = 'salesforce';
public ?string $apiDomain = null;
public bool|string $useSandbox = false;


// Public Methods
// =========================================================================

public function getUseSandbox(): string
{
return App::parseBooleanEnv($this->useSandbox);
}

public function getApiDomain(): string
{
$prefix = $this->getUseSandbox() ? 'test' : 'login';

return "https://{$prefix}.salesforce.com";
}

public function getBaseApiUrl(?Token $token): ?string
{
$url = $this->getApiDomain();

return "$url/services/data/v49.0";
}

public function getOAuthProviderConfig(): array
{
$config = parent::getOAuthProviderConfig();
$config['domain'] = $this->getApiDomain();

return $config;
}

public function getAuthorizationUrlOptions(): array
{
$options = parent::getAuthorizationUrlOptions();

$options['scope'] = [
'api',
'openid',
'refresh_token',
'offline_access',
];

return $options;
}

}
1 change: 1 addition & 0 deletions src/services/Providers.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public function getAllProviderTypes(): array
providerTypes\Pinterest::class,
providerTypes\Pipedrive::class,
providerTypes\Reddit::class,
providerTypes\Salesforce::class,
providerTypes\Shopify::class,
providerTypes\Slack::class,
providerTypes\Snapchat::class,
Expand Down
14 changes: 14 additions & 0 deletions src/templates/providers/salesforce.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{% import '_includes/forms' as forms %}
{% import 'verbb-base/_macros' as macros %}

{% include 'social-login/providers/_oauth' %}

{{ forms.booleanMenuField({
label: 'Use Sandbox' | t('social-login'),
instructions: 'Whether to use the {provider} sandbox.' | t('social-login', { provider: provider.name }),
name: 'useSandbox',
includeEnvVars: true,
value: provider.useSandbox ?? false,
warning: macros.configWarning('useSandbox', 'social-login'),
errors: provider.getErrors('useSandbox'),
}) }}

0 comments on commit d03d824

Please sign in to comment.