Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Server Handling, Secure Bug Fix, Passing custom Data around #53

Merged
merged 11 commits into from
May 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,18 @@ webhook.on('unsubscribe', function (data, meta) {
_MailChimpOAuth_ takes one argument, an options object which can contain the following options:

* `clientId` The clientId can be obtained from MailChimp, please refer to the API docs on how to do this. The clientId is a required parameter.
* `clientSecret` The clientSecret can be obtained from MailChimp, please refer to the API docs on how to do this. The clientSecret is a required parameter.
* `serverUri` The URI to reach this server from the internet. This URI is required as MailChimp sends a request upon successful authorization of a user.
* `redirectUri` After a successful authorization on the MailChimp website the user is redirected to this URI, if any.
* `clientSecret` The clientSecret can be obtained from MailChimp, please refer to the API docs on how to do this. The clientSecret is a required parameter.
* `redirectUri` Redirect URI from MailChimp App Configuration
* `ownServer` Boolean to enable own custom server for listening to redirect URI. Defaults to false.
* `addPort` Boolean to add value of port number in redirectUri defaults to false.
* `port` The port the server is going to listen on. Defaults to 8100.
* `secure` Credentials as generated by the crypto module. If present HTTPS support is enabled for the server. Defaults to false.
These fields are not needed if ownServer is false
* `finalUri` After a successful authorization on the MailChimp website the user is redirected to this URI, if any.
* `secure` Credentials in the form {key:path to ssl key file, cert: path to ssl certificate file} . If present HTTPS support is enabled for the server. Defaults to false.

You can register the following events:

* `error` This event is emitted when an error occured and receives one argument that contains the error message.
* `authed` Emitted when the OAuth was completed successfully. Receives one argument which represents the API key that can be passed on to other API functionality.
* `authed` Emitted when the OAuth was completed successfully. Receives one argument which represents the API key in custom object with metadata that can be passed on to other API functionality.

Example:

Expand All @@ -229,22 +231,24 @@ var MailChimpAPI = require('mailchimp').MailChimpAPI;
var options = {
clientId: 'Your MailChimp client id',
clientSecret: 'Your MailChimp client secret',
serverUri: 'http://www.example.com',
redirectUri: 'http://www.example.com/successfulLogin.html'
redirectUri: 'http://www.example.com',
ownServer: true,
addPort: true,
finalUri: 'http://www.example.com/successfulLogin.html'
};

var oauth = new MailChimpOAuth(options);

console.log(oauth.getAuthorizeUri()); // The MailChimp login URI the user needs to be sent to

<!-- Error contains custom Data when passed around to know the current status-->
oauth.on('error', function (error) {
console.log(error.message);
console.log(error.err);
});

oauth.on('authed', function (apiKey) {
oauth.on('authed', function (data) {

try {
var api = new MailChimpAPI(apiKey, { version : '1.3', secure : false });
var api = new MailChimpAPI(data.apiKey, { version : '1.3', secure : false });
} catch (error) {
console.log(error.message);
}
Expand Down
Loading