Skip to content
This repository has been archived by the owner on Jan 21, 2024. It is now read-only.

Commit

Permalink
adding a new method for OAuth2 first step
Browse files Browse the repository at this point in the history
  • Loading branch information
tbesluau committed Nov 13, 2019
1 parent f502155 commit 8423a95
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ Name | Type | Description | Required
--- | --- | --- | ---
appID | `string` | The installed package ID or appExchange appID in alphanum xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx `string` format | X

### triggerAuth2({authURL: authURL, clientId: clientId, redirectURL: redirectURL})

Opens a hidden iframe to the OAuth2 page for the authURL provided. This will result in the block's server side redirect url (the login URL for the app) to be passed a OAuth2 code so it can request a token.

#### Parameters

Name | Type | Description | Required
--- | --- | --- | ---
authURL | `string` | The enhanced package authURL (auth_uri) in `string` format | X
clientId | `string` | The enhanced package clientId (client_id) in `string` format | X
redirectURL | `string` | The enhanced package redirectURL (redirect_uri) in `string` format | X
scope | `string` array | An array of permissions being requested in [`string`, `string`] format |

## Example

```javascript
Expand Down Expand Up @@ -191,7 +204,7 @@ are `stylingblock` and `htmlblock`. The `object` values must provide the followi
- Type: `string` or `object`
- The name of the tab. If no localization is needed, provide a `string`. If localization is needed,
provide an `object` with key value pairs of the culture code and localized value. If the user's locale
is not provided in the object, Content Builder will first try to use the en-US fallback, then fallback
is not provided in the object, Content Builder will first try to use the en-US fallback, then fallback
to the first value provided.
- Ex: `My Custom Tab` or `{'en-US': 'English Name', 'fr': 'French Name'}`
- `url`
Expand Down Expand Up @@ -239,4 +252,4 @@ Content tab, custom tab with different names depending on the user's language
key: 'localized-tab',
url: 'https://localhost:3000/customtab'
}]
```
```
33 changes: 27 additions & 6 deletions blocksdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var SDK = function (config, whitelistOverride, sslOverride) {

SDK.prototype.execute = function execute (method, options) {
options = options || {};

var self = this;
var payload = options.data;
var callback = options.success;
Expand Down Expand Up @@ -94,27 +94,27 @@ SDK.prototype.setBlockEditorWidth = function (value, cb) {

SDK.prototype.setCentralData = function (dataObj, cb) {
this.execute('setCentralData', {
data: dataObj,
data: dataObj,
success: cb
});
};

SDK.prototype.setContent = function (content, cb) {
this.execute('setContent', {
data: content,
data: content,
success: cb});
};

SDK.prototype.setData = function (dataObj, cb) {
this.execute('setData', {
data: dataObj,
data: dataObj,
success: cb
});
};

SDK.prototype.setSuperContent = function (content, cb) {
this.execute('setSuperContent', {
data: content,
data: content,
success: cb
});
};
Expand All @@ -138,14 +138,35 @@ SDK.prototype.triggerAuth = function (appID) {
});
};

SDK.prototype.triggerAuth2 = function (authInfo) {
var iframe = document.createElement('IFRAME');
var scope = '';
var state = '';
if(Array.isArray(authInfo.scope)) {
scope = '&scope=' + authInfo.scope.join('%20');
}
if(authInfo.state) {
state = '&state=' + authInfo.state;
}
iframe.src = authInfo.authURL + (authInfo.authURL.endsWith('/') ? '':'/') + 'v2/authorize?response_type=code&client_id=' + authInfo.clientId + '&redirect_uri=' + encodeURIComponent(authInfo.redirectURL) + scope + state;
iframe.style.width= '1px';
iframe.style.height = '1px';
iframe.style.position = 'absolute';
iframe.style.top = '0';
iframe.style.left = '0';
iframe.style.visibility = 'hidden';
iframe.className = 'authframe';
document.body.appendChild(iframe);
};

/* Internal Methods */

SDK.prototype._executePendingMessages = function _executePendingMessages () {
var self = this;

this._pendingMessages.forEach(function (thisMessage) {
self.execute(thisMessage.method, {
data: thisMessage.payload,
data: thisMessage.payload,
success: thisMessage.callback
});
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "blocksdk",
"version": "1.1.1",
"version": "1.2.0",
"description": "SDK for 3rd party blocks to communicate with the Salesforce Marketing Cloud Content Builder Editor",
"repository": {
"type": "git",
Expand Down

0 comments on commit 8423a95

Please sign in to comment.