Skip to content

Commit

Permalink
0.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrii-fediuk committed Jul 12, 2017
1 parent c60c660 commit c05ecf7
Show file tree
Hide file tree
Showing 7 changed files with 183 additions and 2 deletions.
1 change: 1 addition & 0 deletions API/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ final protected function headers() {return [
// Transfer-encoding: chunked
// Vary: Accept-Encoding
,'Accept-Encoding' => 'gzip'
,'Authorization' => 'Bearer ' . df_oauth_app($this)->token()
];}

/**
Expand Down
38 changes: 38 additions & 0 deletions Button.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
namespace Dfe\Salesforce;
// 2017-07-10
/** @final Unable to use the PHP «final» keyword here because of the M2 code generation. */
class Button extends \Df\OAuth\FE\Button {
/**
* 2017-07-10
* @override
* @see \Df\OAuth\FE\Button::pExtra()
* @used-by \Df\OAuth\FE\Button::onFormInitialized()
* @return array(string => mixed)
*/
final protected function pExtra() {return df_clean([
/**
* 2017-07-11
* «Specifies a value to be returned in the response; this is useful for detecting "replay" attacks.
* Optional with the openid scope for getting a user ID token.»
* Optional.
* https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_web_server_oauth_flow.htm#nonce_parameter_description
*/
'nonce' => null
/**
* 2017-07-11
* Note 1.
* «Specifies what data your application can access.
* See `Scope Parameter Values` in the online help for more information.»
* Optional.
* https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_web_server_oauth_flow.htm#scope_parameter_description
* Note 2.
* The «Scope Parameter Values» documentation article
* is present only in the «Mobile SDK Development Guide»:
* https://www.google.com/search?q="Scope+Parameter+Values"+site:developer.salesforce.com
* https://developer.salesforce.com/docs/atlas.en-us.mobile_sdk.meta/mobile_sdk/oauth_scope_parameter_values.htm#topic-title
*/
,'scope' => null
]);}
}

48 changes: 48 additions & 0 deletions OAuth/App.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
namespace Dfe\Salesforce\OAuth;
use Df\Core\Exception as DFE;
use Dfe\Salesforce\Settings\General\OAuth as S;
// 2017-07-10
final class App extends \Df\OAuth\App {
/**
* 2017-07-10
* @override
* @see \Df\OAuth\App::ss()
* @used-by \Df\OAuth\App::getAndSaveTheRefreshToken()
* @used-by \Df\OAuth\App::pCommon()
* @used-by \Df\OAuth\App::requestToken()
* @used-by \Df\OAuth\App::token()
* @used-by \Df\OAuth\FE\Button::s()
* @return S
*/
function ss() {return S::s();}

/**
* 2017-07-10
* https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_oauth_endpoints.htm#topic-title
* @override
* @see \Df\OAuth\App::urlAuth()
* @used-by \Df\OAuth\FE\Button::onFormInitialized()
* @return string
*/
function urlAuth() {return self::url('authorize');}

/**
* 2017-07-11
* https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_oauth_endpoints.htm#topic-title
* @override
* @see \Df\OAuth\App::urlToken()
* @used-by \Df\OAuth\App::requestToken()
* @return string
*/
protected function urlToken() {return self::url('token');}

/**
* 2017-07-11
* @used-by urlAuth()
* @used-by urlToken()
* @param string $s
* @return string
*/
private static function url($s) {return "https://login.salesforce.com/services/oauth2/$s";}
}
15 changes: 15 additions & 0 deletions Settings/General/OAuth.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
namespace Dfe\Salesforce\Settings\General;
// 2017-07-10
/** @method static OAuth s() */
final class OAuth extends \Df\OAuth\Settings {
/**
* 2017-07-10
* @override
* @see \Df\Config\Settings::prefix()
* @used-by \Df\Config\Settings::v()
* @used-by \Df\OAuth\Settings::refreshTokenSave()
* @return string
*/
protected function prefix() {return 'df_salesforce/general/oauth';}
}
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mage2pro/salesforce"
,"version": "0.0.4"
,"version": "0.0.5"
,"description": "The «Salesforce» extension for Magento 2."
,"type": "magento2-module"
,"homepage": "https://mage2.pro/c/extensions/salesforce"
Expand All @@ -11,7 +11,7 @@
"homepage": "https://mage2.pro/users/dmitry_fedyuk",
"role": "Developer"
}]
,"require": {"mage2pro/core": ">=2.7.44"}
,"require": {"mage2pro/core": ">=2.8.2"}
,"autoload": {"files": ["registration.php"], "psr-4": {"Dfe\\Salesforce\\": ""}}
,"keywords": [
"API"
Expand Down
10 changes: 10 additions & 0 deletions etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version='1.0'?>
<config
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation='urn:magento:framework:ObjectManager/etc/config.xsd'
>
<virtualType
name='Dfe\Salesforce\Controller\Adminhtml\Oauth\Index'
type='Df\OAuth\ReturnT\GeneralPurpose'
/>
</config>
69 changes: 69 additions & 0 deletions etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,75 @@
</depends>
<validate>required-entry df-validate-domain</validate>
</field>
<group
id='oauth'
showInDefault='1' showInStore='1' showInWebsite='1'
sortOrder='3'
translate='label'
>
<label>OAuth 2.0</label>
<comment><![CDATA[Your Salesforce instance should authenticate your Magento instance by the <a href='https://oauth.net/2/' target='_blank'>OAuth 2.0</a> protocol.]]></comment>
<field
id='clientId'
showInDefault='1' showInStore='1' showInWebsite='1'
sortOrder='1'
translate='label'
type='text'
>
<label>Client Identifier</label>
<comment><![CDATA[An OAuth 2.0 «Client Identifier», as defined in the <a href='https://tools.ietf.org/html/rfc6749#section-2.2' title='RFC 6749 specification, Section 2.2: «Client Identifier»' target='_blank'>section 2.2</a> of the RFC 6749 specification.
<br/>Salesforce <a href='https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_defining_remote_access_applications.htm#intro_defining_remote_access_applications' target='_blank' title='Defining Connected Apps - Force.com REST API Developer Guide'>names</a> this entity as «<b>Consumer Key</b>».
<br/><a href='https://mage2.pro/t/3838' title='How to register a Salesforce Connected App for integration with Magento 2?' target='_blank'>How to get it?</a>]]></comment>
<depends>
<field id='enable'>1</field>
</depends>
<validate>required-entry</validate>
</field>
<field
id='clientPassword'
showInDefault='1' showInStore='1' showInWebsite='1'
sortOrder='2'
translate='label'
type='obscure'
>
<label>Client Password</label>
<comment><![CDATA[The OAuth 2.0 «Client Password» for the «Client Identifier» above, as defined in the <a href='https://tools.ietf.org/html/rfc6749#section-2.3.1' title='RFC 6749 specification, Section 2.3.1: «Client Password»' target='_blank'>section 2.3.1</a> of the RFC 6749 specification.
<br/>Salesforce <a href='https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_defining_remote_access_applications.htm#intro_defining_remote_access_applications' target='_blank' title='Defining Connected Apps - Force.com REST API Developer Guide'>names</a> this entity as «<b>Consumer Secret</b>».
<br/><a href='https://mage2.pro/t/3838' title='How to register a Salesforce Connected App for integration with Magento 2?' target='_blank'>How to get it?</a>]]></comment>
<backend_model>Magento\Config\Model\Config\Backend\Encrypted</backend_model>
<depends>
<field id='enable'>1</field>
</depends>
<validate>required-entry</validate>
</field>
<field
dfWebhook_backend='true'
dfWebhook_suffix='oauth'
id='redirectionEndpoint'
showInDefault='1' showInStore='1' showInWebsite='1'
sortOrder='3'
translate='label'
type='Df\Sso\FE\CustomerReturn'
>
<label>Redirection Endpoint</label>
<comment><![CDATA[The OAuth 2.0 «Redirection Endpoint», as defined in the <a href='https://tools.ietf.org/html/rfc6749#section-3.1.2' title='RFC 6749 specification, Section 3.1.2: «Redirection Endpoint»' target='_blank'>section 3.1.2</a> of the RFC 6749 specification.
<br/>Salesforce <a href='https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_defining_remote_access_applications.htm#intro_defining_remote_access_applications' target='_blank' title='Defining Connected Apps - Force.com REST API Developer Guide'>names</a> this entity as «<b>Callback URL</b>».
<br/>Set it in your Salesforce <a href='https://mage2.pro/t/3838' title='How to register a Salesforce Connected App for integration with Magento 2?' target='_blank'>app registration form</a> (Step 4).]]></comment>
<depends><field id='enable'>1</field></depends>
</field>
<field
id='authenticate'
showInDefault='1' showInWebsite='1' showInStore='1'
sortOrder='4'
type='Dfe\Salesforce\Button'
>
<!-- 2017-06-29
«How to implement a dynamically generated comment for a backend configuration field?»
https://mage2.pro/t/4076 -->
<comment model='Dfe\Salesforce\Button' />
<depends><field id='enable'>1</field></depends>
</field>
</group>
</group>
</section>
</system>
Expand Down

0 comments on commit c05ecf7

Please sign in to comment.