-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5b0590
commit 5e3c751
Showing
19 changed files
with
141 additions
and
47 deletions.
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 |
---|---|---|
@@ -1,3 +1,7 @@ | ||
## 0.9.0 | ||
|
||
* (New) Early Access version of NetLicensing / Zapier integration | ||
|
||
## 0.9.1 | ||
|
||
* API Key authentication added |
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,53 @@ | ||
const constants = require('../config/Constants'); | ||
|
||
const test = (z) => { | ||
// Normally you want to make a request to an endpoint that is either specifically designed to test auth, or one that | ||
// every user will have access to, such as an account or profile endpoint like /me. | ||
// In this example, we'll hit httpbin, which validates the Authorization Header against the arguments passed in the | ||
// URL path | ||
|
||
// This method can return any truthy value to indicate the credentials are valid. | ||
// Raise an error to show | ||
return z.request({ | ||
url: `${constants.BASE_HOST + constants.BASE_PATH}/utility/licensingModels`, | ||
method: 'GET', | ||
headers: { | ||
Accept: 'application/json', | ||
}, | ||
params: {}, | ||
}).then((response) => { | ||
if (response.status === 401) { | ||
throw new Error(constants.authentication.LOGIN_FAILED_TEXT); | ||
} else if (response.status >= 500) { | ||
throw new Error(constants.authentication.SERVICE_UNAVAILABLE_TEXT); | ||
} | ||
return response; | ||
}); | ||
}; | ||
|
||
module.exports = { | ||
type: 'custom', | ||
// The test method allows Zapier to verify that the credentials a user provides are valid. We'll execute this | ||
// method whenver a user connects their account for the first time. | ||
test, | ||
// assuming "username" is a key returned from the test | ||
// connectionLabel: '{{username}}', | ||
fields: [ | ||
{ | ||
key: 'username', | ||
type: 'string', | ||
required: false, | ||
}, | ||
{ | ||
key: 'password', | ||
type: 'password', | ||
required: false, | ||
}, | ||
{ | ||
key: 'apiKey', | ||
type: 'string', | ||
required: false, | ||
helpText: 'You could authenticate by Username and Password or API Key', | ||
}, | ||
], | ||
}; |
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
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
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,37 @@ | ||
const nock = require('nock'); | ||
|
||
const zapier = require('zapier-platform-core'); | ||
|
||
const constants = require('../../../config/Constants'); | ||
|
||
// Use this to make test calls into your app: | ||
const App = require('../../../index'); | ||
|
||
const appTester = zapier.createAppTester(App); | ||
|
||
describe('Authentication', () => { | ||
const apiMock = nock(constants.BASE_HOST); | ||
const authData = { | ||
username: '', | ||
password: '', | ||
apiKey: 'testApiKey', | ||
}; | ||
|
||
afterEach(() => { | ||
nock.cleanAll(); | ||
}); | ||
|
||
it('Success auth', (done) => { | ||
const bundle = Object.assign({}, { authData }); | ||
|
||
apiMock.get(`${constants.BASE_PATH}/utility/licensingModels`) | ||
.reply(200); | ||
|
||
appTester(App.authentication.test, bundle) | ||
.then((response) => { | ||
response.status.should.eql(200); | ||
done(); | ||
}) | ||
.catch(done); | ||
}); | ||
}); |
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
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
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
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,14 @@ | ||
const { Context, Constants } = require('netlicensing-client/dist/netlicensing-client.node'); | ||
|
||
module.exports = (bundle) => { | ||
const context = new Context(); | ||
if (bundle.authData.username.trim() && bundle.authData.password.trim()) { | ||
context.setUsername(bundle.authData.username); | ||
context.setPassword(bundle.authData.password); | ||
context.setSecurityMode(Constants.BASIC_AUTHENTICATION); | ||
} else { | ||
context.setApiKey(bundle.authData.apiKey); | ||
context.setSecurityMode(Constants.APIKEY_IDENTIFICATION); | ||
} | ||
return context; | ||
}; |