@ntnx/passport-wso2 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.jshintignore ADDED
@@ -0,0 +1 @@
1
+ node_modules/**
package/.jshintrc ADDED
@@ -0,0 +1,23 @@
1
+ //
2
+ // JS Hint. See options here:
3
+ // http://www.jshint.com/docs/options
4
+ //
5
+ {
6
+ "camelcase": true, // Force all variable names to use camelCase style
7
+ "curly": true, // Require {} for every new block or scope
8
+ "eqeqeq": true, // Require triple equals (===) for comparison
9
+ "eqnull": false, // Tolerate use of `== null`
10
+ "evil": false, // Tolerate use of `eval`
11
+ "immed": true, // Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
12
+ "latedef": "nofunc", // Require variables to be defined before being used
13
+ "laxbreak": false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
14
+ "laxcomma": true, // Allow for comma-first coding style
15
+ "maxerr": 100, // Maximum error before stopping.
16
+ "maxlen": 80, // Maximum line length
17
+ "newcap": true, // Require capitalization of all constructor functions e.g. `new F()`
18
+ "node": true, // Ignore standard node.js globals
19
+ "quotmark": "single", // Enforces the consistency of quotation marks used throughout your code
20
+ "shadow": false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
21
+ "undef": true, // Require all non-global variables to be declared (prevents global leaks)
22
+ "unused": false, // Prohibits the use of explicitly undeclared variables
23
+ }
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Jason Sims
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ passport-wso2
2
+ =============
3
+ WSO2 Identity Server authentication strategy for Passport and Node.js.
4
+ > **Note:** This repo is still a work in progress. As soon as the first stable version is available I'll get it published to NPM and listed on the [passport providers](http://passportjs.org/guide/providers/) page.
5
+
6
+
7
+ ## Installation
8
+ ```sh
9
+ npm install git+https://github.com/jasonsims/passport-wso2.git#master
10
+ ```
11
+
12
+ ## Usage
13
+ TODO
14
+
15
+ ## Examples
16
+ TODO
17
+
18
+
package/lib/index.js ADDED
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Module dependencies.
3
+ */
4
+ var Strategy = require('./strategy');
5
+
6
+
7
+ /**
8
+ * Expose `Strategy` directly from package.
9
+ */
10
+ exports = module.exports = Strategy;
11
+
12
+ /**
13
+ * Export constructors.
14
+ */
15
+ exports.Strategy = Strategy;
package/lib/profile.js ADDED
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Parse profile.
3
+ *
4
+ * This parser normalizes the JSON representation of the user profile, as given
5
+ * by the auth provider, in accordance with the portable contacts spec.
6
+ * http://portablecontacts.net/draft-spec.html
7
+ *
8
+ * @param {Object} Profile JSON from provider
9
+ * @return {Object}
10
+ * @api private
11
+ */
12
+ exports.parse = function(json) {
13
+ var _json = {};
14
+ //
15
+ // there is a change in idp v5.2 profile information. Resources key is not
16
+ // available in idp v5.2. Modified below code to support new changes.
17
+ //
18
+ // Sample format for the both versions
19
+ // idp v5.0: {Resources: [userName: 'test@nutanix.com']}
20
+ // idp v5.2: {userName: 'test@nutanix.com'}
21
+ //
22
+ if (json && json.Resources && json.Resources[0]) {
23
+ _json = json.Resources[0];
24
+ } else {
25
+ _json = json;
26
+ }
27
+
28
+ var profile = {};
29
+
30
+ profile.id = String(_json.id);
31
+ profile.name = _parseName(_json);
32
+ profile.displayName = _parseDisplayName(_json);
33
+ profile.userName = _json.userName;
34
+ profile.emails = _parseEmails(_json);
35
+ profile.groups = _json.groups;
36
+
37
+ return profile;
38
+ };
39
+
40
+ //
41
+ // Private
42
+ //
43
+ function _parseName(json) {
44
+ return json.name || {givenName: '', familyName: ''}
45
+ }
46
+
47
+ function _parseDisplayName(json) {
48
+ var nameObj = json.name || {}
49
+ var nameItems = []
50
+ if (nameObj.givenName) {nameItems.push(nameObj.givenName)}
51
+ if (nameObj.familyName) {nameItems.push(nameObj.familyName)}
52
+
53
+ return nameItems.join(' ')
54
+ }
55
+
56
+ function _parseEmails(json) {
57
+ var emails = [];
58
+ var toParse = json.emails || [];
59
+
60
+ // Normalize user email list. The WSO2 API maintains the email list in a
61
+ // strage way returning the primary email as a string elment in the `emails`
62
+ // array but includes everything else as an object.
63
+ toParse.forEach(function(val, idx) {
64
+ var emailObj = (typeof val === 'string') ?
65
+ {type: 'primary', value: val} : val
66
+ emails.push(emailObj);
67
+ })
68
+
69
+ return emails;
70
+ }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * Module dependencies.
3
+ */
4
+ var util = require('util');
5
+ var OAuth2Strategy = require('passport-oauth2');
6
+ var InternalOAuthError = require('passport-oauth2').InternalOAuthError;
7
+ var Profile = require('./profile');
8
+
9
+
10
+ /**
11
+ * `Strategy` constructor.
12
+ *
13
+ * The WSO2 authentication strategy authenticates requests by delegating to a
14
+ * WSO2 Identity Server using the OAuth 2.0 protocol.
15
+ *
16
+ * Applications must supply a `verify` callback which accepts an `accessToken`,
17
+ * `refreshToken` and service-specific `profile`, and then calls the `done`
18
+ * callback supplying a `user`, which should be set to `false` if the
19
+ * credentials are not valid. If an exception occured, `err` should be set.
20
+ *
21
+ * Options:
22
+ * - `clientID` your WSO2 service provider's Client ID
23
+ * - `clientSecret` your WSO2 service provider's Client Secret
24
+ * - `callbackURL` URL to which WSO2 will redirect the user after
25
+ * granting authorization
26
+ *
27
+ * @param {Object} options
28
+ * @param {Function} verify
29
+ * @api public
30
+ */
31
+ function Strategy(options, verify) {
32
+ options = options || {};
33
+
34
+ OAuth2Strategy.call(this, options, verify);
35
+ this.name = options.strategyName || 'wso2';
36
+ this._oauth2.useAuthorizationHeaderforGET(true);
37
+ this._authorizationParams = options.authorizationParams || {}
38
+ this._tokenParams = options.tokenParams || {}
39
+ // TODO: We should be able to assume the user profile URL based on the
40
+ // hostname of the identity provider since the endpoint should always
41
+ // be /wso2/scim/Users/me.
42
+ this._userProfileURL = options.userProfileURL;
43
+ }
44
+
45
+ /**
46
+ * Inherit from `OAuth2Strategy`.
47
+ */
48
+ util.inherits(Strategy, OAuth2Strategy);
49
+
50
+ /**
51
+ * Retrieve user profile from the WSO2 Identity Server.
52
+ *
53
+ * @override
54
+ * @param {String} accessToken
55
+ * @param {Function} done
56
+ * @api protected
57
+ */
58
+ Strategy.prototype.userProfile = function(accessToken, done) {
59
+ this._oauth2.get(this._userProfileURL, accessToken, function(err, body, res) {
60
+ var json;
61
+ var profile;
62
+
63
+ if (err) {
64
+ return done(new InternalOAuthError('Failed to fetch user profile', err));
65
+ }
66
+
67
+ try {
68
+ json = JSON.parse(body)
69
+ } catch (ex) {
70
+ return done(new Error('Failed to parse user profile'))
71
+ }
72
+
73
+ profile = Profile.parse(json)
74
+ profile.provider = 'wso2'
75
+ profile._raw = body
76
+ profile._json = json
77
+
78
+ done(null, profile)
79
+ })
80
+ }
81
+
82
+ /**
83
+ * Return extra parameters to be included in the authorization request.
84
+ *
85
+ * @override
86
+ * @param {Object} options
87
+ * @return {Object}
88
+ * @api protected
89
+ */
90
+ Strategy.prototype.authorizationParams = function(options) {
91
+ return JSON.parse(JSON.stringify(this._authorizationParams));
92
+ }
93
+
94
+ /**
95
+ * Return extra parameters to be included in the token request.
96
+ *
97
+ * @override
98
+ * @return {Object}
99
+ * @api protected
100
+ */
101
+ Strategy.prototype.tokenParams = function(options) {
102
+ return JSON.parse(JSON.stringify(this._tokenParams));
103
+ }
104
+
105
+ /**
106
+ * Expose `Strategy`.
107
+ */
108
+ module.exports = Strategy;
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@ntnx/passport-wso2",
3
+ "version": "0.0.2",
4
+ "description": "WSO2 Identity Server authentication strategy for Passport.",
5
+ "main": "./lib",
6
+ "author": "Jason Sims <sims.jrobert@gmail.com>",
7
+ "keywords": [
8
+ "passport",
9
+ "wso2",
10
+ "auth",
11
+ "authn",
12
+ "authentication",
13
+ "identity"
14
+ ],
15
+ "scripts": {},
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "git+https://github.com/jasonsims/passport-wso2.git"
19
+ },
20
+ "license": "MIT",
21
+ "bugs": {
22
+ "url": "https://github.com/jasonsims/passport-wso2/issues"
23
+ },
24
+ "homepage": "https://github.com/jasonsims/passport-wso2",
25
+ "dependencies": {
26
+ "passport-oauth2": "^1.1.2"
27
+ },
28
+ "directories": {
29
+ "lib": "lib"
30
+ }
31
+ }