This repository has been archived by the owner on Jun 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 66
Adding more auth conversion templates #167
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
fe1f44a
Adding more auth conversion templates
dbb7521
Marking clearer to-dos
0d5f86b
Adding more auth conversions and tests
139f339
Adding scripting generation and package.json improvements.
b135bb5
Switching version.
df03a42
Skipping test that's killing Travis
4e267e5
Merge branch 'master' into feature-convert-more-auths
ce50077
Fixing redundant comma for convert on index
1cf7e7b
Renaming from interpreter to legacy-scripting-runner
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,9 +16,9 @@ | |
"version": "npm run docs && npm run gen-completions && git add docs/* goodies/* README.md", | ||
"postversion": "git push && git push --tags && npm publish", | ||
"prepublish": "npm run build", | ||
"build": "rm -rf lib && node_modules/babel-cli/bin/babel.js src -d lib", | ||
"watch": "rm -rf lib && node_modules/babel-cli/bin/babel.js --watch src -d lib", | ||
"lint": "node_modules/.bin/eslint zapier.js src test", | ||
"build": "rm -rf lib && node_modules/babel-cli/bin/babel.js src -d lib --copy-files", | ||
"watch": "rm -rf lib && node_modules/babel-cli/bin/babel.js --watch src -d lib --copy-files", | ||
"lint": "node_modules/.bin/eslint zapier.js src", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reasons why we don't want to lint test code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're still linting the test code, since it's inside |
||
"lint-snippets": "node_modules/.bin/eslint snippets --rule 'no-unused-vars: 0'", | ||
"test": "npm run build && node_modules/mocha/bin/mocha -t 15000 --recursive lib/tests && npm run lint && npm run lint-snippets", | ||
"zapier": "zapier.js", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<% if (before && !session && !oauth) { %>const maybeIncludeAuth = (request, z, bundle) => { | ||
<% | ||
Object.keys(mapping).forEach((mapperKey) => { | ||
fields.forEach((field) => { | ||
if (mapping[mapperKey].indexOf(`{{${field}}}`) !== -1) { | ||
if (query) { %> | ||
request.params['<%= mapperKey %>'] = bundle.authData['<%= field %>']; | ||
<% } else { %> | ||
request.headers['<%= mapperKey %>'] = bundle.authData['<%= field %>']; | ||
<% } | ||
} | ||
}); | ||
}); | ||
%> | ||
return request; | ||
} | ||
<% } | ||
|
||
if (before && session) { %>const maybeIncludeAuth = (request, z, bundle) => { | ||
<% | ||
if (query) { %> | ||
request.params['<%= Object.keys(mapping)[0] %>'] = bundle.authData.sessionKey;; | ||
<% } else { %> | ||
request.headers['<%= Object.keys(mapping)[0] %>'] = bundle.authData.sessionKey; | ||
<% } %> | ||
return request; | ||
} | ||
<% } | ||
|
||
if (before && oauth) { %>const maybeIncludeAuth = (request, z, bundle) => { | ||
|
||
request.headers.Authorization = `Bearer ${bundle.authData.access_token}`; | ||
|
||
return request; | ||
} | ||
<% } | ||
|
||
if (after) { %> | ||
const maybeRefresh = (response, z, bundle) => { | ||
if (response.status === 401 || response.status === 403) { | ||
throw new z.errors.RefreshAuthError('Session key needs refreshing.'); | ||
} | ||
|
||
return response; | ||
} | ||
|
||
<% } | ||
|
||
if (session) { %> | ||
const getSessionKey = (z, bundle) => { | ||
const scripting = require('../scripting'); | ||
const legacyScriptingRunner = require('zapier-platform-legacy-scripting-runner')(scripting); | ||
|
||
// Do a get_session_info() from scripting. | ||
const getSessionEvent = { | ||
name: 'auth.session' | ||
}; | ||
return legacyScriptingRunner.runEvent(getSessionEvent, z, bundle) | ||
.then((getSessionResult) => { | ||
// IMPORTANT NOTE: | ||
// WB apps in scripting's get_session_info() allowed to return any object and that would be | ||
// added to the authData, but CLI apps require you to specifically define those. | ||
// That means that if you return more than one key from your scripting's get_session_info(), | ||
// you might need to manually tweak this method to return that value at the end of this method, | ||
// and also add more fields to the authentication definition. | ||
|
||
const resultKeys = Object.keys(getSessionResult); | ||
const firstKeyValue = (getSessionResult && resultKeys.length > 0) ? getSessionResult[resultKeys[0]] : getSessionResult; | ||
|
||
return { | ||
sessionKey: firstKeyValue | ||
}; | ||
}); | ||
} | ||
<% } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
// TODO: just an example stub - you'll need to complete | ||
type: 'oauth2', | ||
test: AuthTest.operation.perform, | ||
oauth2Config: { | ||
authorizeUrl: { | ||
method: 'GET', | ||
url: '<%= AUTHORIZE_URL %>', | ||
params: { | ||
client_id: '{{process.env.CLIENT_ID}}', | ||
state: '{{bundle.inputData.state}}', | ||
redirect_uri: '{{bundle.inputData.redirect_uri}}', | ||
response_type: 'code' | ||
} | ||
}, | ||
getAccessToken: { | ||
method: 'POST', | ||
url: '<%= ACCESS_TOKEN_URL %>', | ||
body: { | ||
code: '{{bundle.inputData.code}}', | ||
client_id: '{{process.env.CLIENT_ID}}', | ||
client_secret: '{{process.env.CLIENT_SECRET}}', | ||
redirect_uri: '{{bundle.inputData.redirect_uri}}', | ||
grant_type: 'authorization_code' | ||
}, | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
}, | ||
refreshAccessToken: { | ||
method: 'POST', | ||
url: '<%= REFRESH_TOKEN_URL %>', | ||
body: { | ||
refresh_token: '{{bundle.authData.refresh_token}}', | ||
client_id: '{{process.env.CLIENT_ID}}', | ||
client_secret: '{{process.env.CLIENT_SECRET}}', | ||
grant_type: 'refresh_token' | ||
}, | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
} | ||
}, | ||
scope: '<%= SCOPE %>', | ||
autoRefresh: true | ||
}, | ||
connectionLabel: '<%= CONNECTION_LABEL %>' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
// START: HEADER -- AUTOMATICALLY ADDED FOR COMPATIBILITY - v<%= VERSION %> | ||
const _ = require('lodash'); | ||
_.templateSettings.interpolate = /{{([\s\S]+?)}}/g; | ||
const crypto = require('crypto'); | ||
const async = require('async'); | ||
const moment = require('moment-timezone'); | ||
const DOMParser = require('zapier-platform-legacy-scripting-runner/dom-parser'); | ||
const XMLSerializer = require('zapier-platform-legacy-scripting-runner/xml-serializer'); | ||
const atob = require('zapier-platform-legacy-scripting-runner/atob'); | ||
const btoa = require('zapier-platform-legacy-scripting-runner/btoa'); | ||
const z = require('zapier-platform-legacy-scripting-runner/z'); | ||
const $ = require('zapier-platform-legacy-scripting-runner/$'); | ||
const { | ||
ErrorException, | ||
HaltedException, | ||
StopRequestException, | ||
ExpiredAuthException, | ||
RefreshTokenException, | ||
InvalidSessionException, | ||
} = require('zapier-platform-legacy-scripting-runner/exceptions'); | ||
// END: HEADER -- AUTOMATICALLY ADDED FOR COMPATIBILITY - v<%= VERSION %> | ||
|
||
<%= CODE %> | ||
|
||
// START: FOOTER -- AUTOMATICALLY ADDED FOR COMPATIBILITY - v<%= VERSION %> | ||
module.exports = Zap; | ||
// END: FOOTER -- AUTOMATICALLY ADDED FOR COMPATIBILITY - v<%= VERSION %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
// TODO: just an example stub - you'll need to complete | ||
type: 'session', | ||
test: AuthTest.operation.perform, | ||
fields: [ | ||
<%= FIELDS %> | ||
], | ||
sessionConfig: { | ||
perform: getSessionKey | ||
}, | ||
connectionLabel: '<%= CONNECTION_LABEL %>' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just want to clarify. What does
--copy-files
option do? I compared the results with or without--copy-files
. They look the same to me.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It copies the
definitions/*.json
files insidesrc/tests/utils
, otherwise only the.js
files are passed along, at least for me.