diff --git a/modules/default/calendar.zip b/modules/default/calendar.zip new file mode 100644 index 00000000..91ccaeab Binary files /dev/null and b/modules/default/calendar.zip differ diff --git a/modules/default/calendar/README.md b/modules/default/calendar/README.md index 57a989a8..655ab89c 100644 --- a/modules/default/calendar/README.md +++ b/modules/default/calendar/README.md @@ -53,25 +53,36 @@ The `colored` property gives the option for an individual color for each calenda #### Default value: ````javascript config: { - colored: false, + colored: false, calendars: [ { url: 'http://www.calendarlabs.com/templates/ical/US-Holidays.ics', symbol: 'calendar', + auth: { + user: 'username', + pass: 'superstrongpassword', + method: 'basic' + } }, ], } ```` - #### Calendar configuration options: | Option | Description | --------------------- | ----------- | `url` | The url of the calendar .ical. This property is required.

**Possible values:** Any public accessble .ical calendar. | `symbol` | The symbol to show in front of an event. This property is optional.

**Possible values:** See [Font Awesome](http://fontawesome.io/icons/) website. -| `color` | The font color of an event from this calendar. This property should be set if the config is set to colored: true.

**Possible values:** HEX, RGB or RGBA values (#efefef, rgb(242,242,242), rgba(242,242,242,0.5)). +| `color` | The font color of an event from this calendar. This property should be set if the config is set to colored: true.

**Possible values:** HEX, RGB or RGBA values (#efefef, rgb(242,242,242), rgba(242,242,242,0.5)). | `repeatingCountTitle` | The count title for yearly repating events in this calendar.

**Example:** `'Birthday'` -| `user` | The username for HTTP Basic authentication. -| `pass` | The password for HTTP Basic authentication. | `maximumEntries` | The maximum number of events shown. Overrides global setting. **Possible values:** `0` - `100` | `maximumNumberOfDays` | The maximum number of days in the future. Overrides global setting +| `auth` | The object containing options for authentication against the calendar. + + +#### Calendar authentication options: +| Option | Description +| --------------------- | ----------- +| `user` | The username for HTTP authentication. +| `pass` | The password for HTTP authentication. (If you use Bearer authentication, this should be your BearerToken.) +| `method` | Which authentication method should be used. HTTP Basic, Digest and Bearer authentication methods are supported. Basic authentication is used by default if this option is omitted. **Possible values:** `digest`, `basic`, `bearer` **Default value:** `basic` diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 644fc1f6..79e9edca 100644 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -72,10 +72,18 @@ Module.register("calendar", { var calendarConfig = { maximumEntries: calendar.maximumEntries, - maximumNumberOfDays: calendar.maximumNumberOfDays, + maximumNumberOfDays: calendar.maximumNumberOfDays }; - this.addCalendar(calendar.url, calendar.user, calendar.pass, calendarConfig); + // we check user and password here for backwards compatibility with old configs + if(calendar.user && calendar.pass){ + calendar.auth = { + user: calendar.user, + pass: calendar.pass + } + } + + this.addCalendar(calendar.url, calendar.auth, calendarConfig); } this.calendarData = {}; @@ -313,14 +321,13 @@ Module.register("calendar", { * * argument url string - Url to add. */ - addCalendar: function (url, user, pass, calendarConfig) { + addCalendar: function (url, auth, calendarConfig) { this.sendSocketNotification("ADD_CALENDAR", { url: url, maximumEntries: calendarConfig.maximumEntries || this.config.maximumEntries, maximumNumberOfDays: calendarConfig.maximumNumberOfDays || this.config.maximumNumberOfDays, fetchInterval: this.config.fetchInterval, - user: user, - pass: pass + auth: auth }); }, diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index d5ca075e..4728ffae 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -8,7 +8,7 @@ var ical = require("./vendor/ical.js"); var moment = require("moment"); -var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumberOfDays, user, pass) { +var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumberOfDays, auth) { var self = this; var reloadTimer = null; @@ -32,11 +32,23 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe } }; - if (user && pass) { - opts.auth = { - user: user, - pass: pass, - sendImmediately: true + if (auth) { + if(auth.method === 'bearer'){ + opts.auth = { + bearer: auth.pass + } + + }else{ + opts.auth = { + user: auth.user, + pass: auth.pass + }; + + if(auth.method === 'digest'){ + opts.auth.sendImmediately = false; + }else{ + opts.auth.sendImmediately = true; + } } } @@ -47,7 +59,7 @@ var CalendarFetcher = function(url, reloadInterval, maximumEntries, maximumNumbe return; } - //console.log(data); + // console.log(data); newEvents = []; var limitFunction = function(date, i) {return i < maximumEntries;}; diff --git a/modules/default/calendar/debug.js b/modules/default/calendar/debug.js index 9b72d51d..ddf0fb42 100644 --- a/modules/default/calendar/debug.js +++ b/modules/default/calendar/debug.js @@ -8,14 +8,22 @@ var CalendarFetcher = require("./calendarfetcher.js"); -var url = "https://calendar.google.com/calendar/ical/pkm1t2uedjbp0uvq1o7oj1jouo%40group.calendar.google.com/private-08ba559f89eec70dd74bbd887d0a3598/basic.ics"; +var url = "https://calendar.google.com/calendar/ical/pkm1t2uedjbp0uvq1o7oj1jouo%40group.calendar.google.com/private-08ba559f89eec70dd74bbd887d0a3598/basic.ics"; // Standard test URL +// var url = "https://www.googleapis.com/calendar/v3/calendars/primary/events/"; // URL for Bearer auth (must be configured in Google OAuth2 first) var fetchInterval = 60 * 60 * 1000; var maximumEntries = 10; var maximumNumberOfDays = 365; +var user = "magicmirror"; +var pass = "MyStrongPass"; + +var auth = { + user: user, + pass: pass +}; console.log("Create fetcher ..."); -fetcher = new CalendarFetcher(url, fetchInterval, maximumEntries, maximumNumberOfDays); +fetcher = new CalendarFetcher(url, fetchInterval, maximumEntries, maximumNumberOfDays, auth); fetcher.onReceive(function(fetcher) { console.log(fetcher.events()); @@ -29,4 +37,4 @@ fetcher.onError(function(fetcher, error) { fetcher.startFetch(); -console.log("Create fetcher done! "); +console.log("Create fetcher done! "); \ No newline at end of file diff --git a/modules/default/calendar/node_helper.js b/modules/default/calendar/node_helper.js index cc511659..90c286c8 100644 --- a/modules/default/calendar/node_helper.js +++ b/modules/default/calendar/node_helper.js @@ -24,7 +24,7 @@ module.exports = NodeHelper.create({ socketNotificationReceived: function(notification, payload) { if (notification === "ADD_CALENDAR") { //console.log('ADD_CALENDAR: '); - this.createFetcher(payload.url, payload.fetchInterval, payload.maximumEntries, payload.maximumNumberOfDays, payload.user, payload.pass); + this.createFetcher(payload.url, payload.fetchInterval, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth); } }, @@ -36,7 +36,7 @@ module.exports = NodeHelper.create({ * attribute reloadInterval number - Reload interval in milliseconds. */ - createFetcher: function(url, fetchInterval, maximumEntries, maximumNumberOfDays, user, pass) { + createFetcher: function(url, fetchInterval, maximumEntries, maximumNumberOfDays, auth) { var self = this; if (!validUrl.isUri(url)) { @@ -47,7 +47,7 @@ module.exports = NodeHelper.create({ var fetcher; if (typeof self.fetchers[url] === "undefined") { console.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval); - fetcher = new CalendarFetcher(url, fetchInterval, maximumEntries, maximumNumberOfDays, user, pass); + fetcher = new CalendarFetcher(url, fetchInterval, maximumEntries, maximumNumberOfDays, auth); fetcher.onReceive(function(fetcher) { //console.log('Broadcast events.');