openid 2.0.12 → 2.0.14
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/.gitattributes +5 -5
- package/LICENSE +19 -19
- package/README.md +137 -137
- package/SECURITY.md +5 -5
- package/http.js +63 -58
- package/lib/xrds.js +102 -102
- package/openid.js +1373 -1610
- package/package.json +47 -45
- package/sample.js +118 -129
- package/test/cancelled_authentication.test.js +37 -38
- package/test/extensions.test.js +65 -66
- package/test/faulty_assertions.test.js +51 -51
- package/test/full_authentication_tests.test.js +89 -0
- package/test/integration_tests.test.js +161 -166
- package/test/xrds.test.js +42 -42
- package/test/xrds_discovery.test.js +60 -59
- package/expressjs_sample/authentication_controller.js +0 -43
- package/expressjs_sample/login.jade +0 -11
package/.gitattributes
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# Normalize line endings to LF for text files
|
|
2
|
-
* text=auto
|
|
3
|
-
|
|
4
|
-
# Explicitly declare JS files as text
|
|
5
|
-
*.js text
|
|
1
|
+
# Normalize line endings to LF for text files
|
|
2
|
+
* text=auto
|
|
3
|
+
|
|
4
|
+
# Explicitly declare JS files as text
|
|
5
|
+
*.js text
|
package/LICENSE
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
Copyright (C) 2010 by Håvard Stranden.
|
|
2
|
-
|
|
3
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
in the Software without restriction, including without limitation the rights
|
|
6
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
furnished to do so, subject to the following conditions:
|
|
9
|
-
|
|
10
|
-
The above copyright notice and this permission notice shall be included in
|
|
11
|
-
all copies or substantial portions of the Software.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
THE SOFTWARE.
|
|
1
|
+
Copyright (C) 2010 by Håvard Stranden.
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,138 +1,138 @@
|
|
|
1
|
-
# OpenID for Node.js
|
|
2
|
-
|
|
3
|
-
OpenID for Node.js is (yes, you guessed it) an OpenID implementation for Node.js.
|
|
4
|
-
|
|
5
|
-
Highlights and features include:
|
|
6
|
-
|
|
7
|
-
- Full OpenID 1.0/1.1/2.0 compliant Relying Party (client) implementation
|
|
8
|
-
- Very simple API
|
|
9
|
-
- Simple extension points for association state
|
|
10
|
-
|
|
11
|
-
## Download
|
|
12
|
-
|
|
13
|
-
The library can be [reviewed and retrieved from GitHub](http://github.com/havard/node-openid).
|
|
14
|
-
|
|
15
|
-
## Installation
|
|
16
|
-
|
|
17
|
-
If you use [`npm`](http://npmjs.org), simply do `npm install openid`.
|
|
18
|
-
|
|
19
|
-
Otherwise, you can grab the code from [GitHub](https://github.com/havard/node-openid).
|
|
20
|
-
|
|
21
|
-
## Examples
|
|
22
|
-
|
|
23
|
-
Here's a very simple server using OpenID for Node.js for authentication:
|
|
24
|
-
|
|
25
|
-
```javascript
|
|
26
|
-
var openid = require('openid');
|
|
27
|
-
var url = require('url');
|
|
28
|
-
var querystring = require('querystring');
|
|
29
|
-
var relyingParty = new openid.RelyingParty(
|
|
30
|
-
'http://example.com/verify', // Verification URL (yours)
|
|
31
|
-
null, // Realm (optional, specifies realm for OpenID authentication)
|
|
32
|
-
false, // Use stateless verification
|
|
33
|
-
false, // Strict mode
|
|
34
|
-
[]); // List of extensions to enable and include
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
var server = require('http').createServer(
|
|
38
|
-
function(req, res)
|
|
39
|
-
{
|
|
40
|
-
var parsedUrl = url.parse(req.url);
|
|
41
|
-
if(parsedUrl.pathname == '/authenticate')
|
|
42
|
-
{
|
|
43
|
-
// User supplied identifier
|
|
44
|
-
var query = querystring.parse(parsedUrl.query);
|
|
45
|
-
var identifier = query.openid_identifier;
|
|
46
|
-
|
|
47
|
-
// Resolve identifier, associate, and build authentication URL
|
|
48
|
-
relyingParty.authenticate(identifier, false, function(error, authUrl)
|
|
49
|
-
{
|
|
50
|
-
if (error)
|
|
51
|
-
{
|
|
52
|
-
res.writeHead(200);
|
|
53
|
-
res.end('Authentication failed: ' + error.message);
|
|
54
|
-
}
|
|
55
|
-
else if (!authUrl)
|
|
56
|
-
{
|
|
57
|
-
res.writeHead(200);
|
|
58
|
-
res.end('Authentication failed');
|
|
59
|
-
}
|
|
60
|
-
else
|
|
61
|
-
{
|
|
62
|
-
res.writeHead(302, { Location: authUrl });
|
|
63
|
-
res.end();
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
else if(parsedUrl.pathname == '/verify')
|
|
68
|
-
{
|
|
69
|
-
// Verify identity assertion
|
|
70
|
-
// NOTE: Passing just the URL is also possible
|
|
71
|
-
relyingParty.verifyAssertion(req, function(error, result)
|
|
72
|
-
{
|
|
73
|
-
res.writeHead(200);
|
|
74
|
-
res.end(!error && result.authenticated
|
|
75
|
-
? 'Success :)'
|
|
76
|
-
: 'Failure :(');
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
else
|
|
80
|
-
{
|
|
81
|
-
// Deliver an OpenID form on all other URLs
|
|
82
|
-
res.writeHead(200);
|
|
83
|
-
res.end('<!DOCTYPE html><html><body>'
|
|
84
|
-
+ '<form method="get" action="/authenticate">'
|
|
85
|
-
+ '<p>Login using OpenID</p>'
|
|
86
|
-
+ '<input name="openid_identifier" />'
|
|
87
|
-
+ '<input type="submit" value="Login" />'
|
|
88
|
-
+ '</form></body></html>');
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
server.listen(80);
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
A more elaborate example including extensions can be found in `sample.js` in the GitHub repository.
|
|
95
|
-
|
|
96
|
-
## Supported Extensions
|
|
97
|
-
This library comes with built-in support for the following OpenID extensions:
|
|
98
|
-
|
|
99
|
-
- The Simple Registration (SREG) 1.1 extension is implemented as `openid.SimpleRegistration`.
|
|
100
|
-
- The Attribute Exchange (AX) 1.0 extension is implemented as `openid.AttributeExchange`.
|
|
101
|
-
- The OAuth 1.0 extension is implemented as `openid.OAuthHybrid`.
|
|
102
|
-
- The User Interface 1.0 extension is implemented as `openid.UserInterface`.
|
|
103
|
-
- The Provider Authentication Policy Extension 1.0 (PAPE) is implemented as `openid.pape`.
|
|
104
|
-
|
|
105
|
-
## Storing association state
|
|
106
|
-
|
|
107
|
-
To provide a way to save/load association state, you need to mix-in two functions in
|
|
108
|
-
the `openid` module:
|
|
109
|
-
|
|
110
|
-
- `saveAssociation(provider, type, handle, secret, expiry_time_in_seconds, callback)` is called when a new association is established during authentication. The callback should be called with any error as its first argument (or `null` if no error occured).
|
|
111
|
-
- `loadAssociation(handle, callback)` is used to retrieve the association identified by `handle` when verification happens. The callback should be called with any error as its first argument (and `null` as the second argument), or an object with the keys `provider`, `type`, `secret` if the association was loaded successfully.
|
|
112
|
-
|
|
113
|
-
The `openid` module includes default implementations for these functions using a simple object to store the associations in-memory.
|
|
114
|
-
|
|
115
|
-
## Caching discovered information
|
|
116
|
-
|
|
117
|
-
The verification of a positive assertion (i.e. an authenticated user) can be sped up significantly by avoiding the need for additional provider discoveries when possible. In order to achieve, this speed-up, node-openid needs to cache its discovered providers. You can mix-in two functions to override the default cache, which is an in-memory cache utilizing a simple object store:
|
|
118
|
-
|
|
119
|
-
- `saveDiscoveredInformation(key, provider, callback)` is used when saving a discovered provider. The following behavior is required:
|
|
120
|
-
- The `key` parameter should be uses as a key for storing the provider - it will be used as the lookup key when loading the provider. (Currently, the key is either a claimed identifier or an OP-local identifier, depending on the OpenID context.)
|
|
121
|
-
- When saving fails for some reason, `callback(error)` is called with `error` being an error object specifying what failed.
|
|
122
|
-
- When saving succeeds, `callback(null)` is called.
|
|
123
|
-
|
|
124
|
-
- `loadDiscoveredInformation(key, callback)` is used to load any previously discovered information about the provider for an identifier. The following behavior is required:
|
|
125
|
-
- When no provider is found for the identifier, `callback(null, null)` is called (i.e. it is not an error to not have any data to return).
|
|
126
|
-
- When loading fails for some reason, `callback(error, null)` is called with `error` being an error string specifying why loading failed.
|
|
127
|
-
- When loading succeeds, `callback(null, provider)` is called with the exact provider object that was previously stored using `saveDiscoveredInformation`.
|
|
128
|
-
|
|
129
|
-
## Proxy Support
|
|
130
|
-
`node-openid` makes HTTP and HTTPS requests during authentication. You can have these
|
|
131
|
-
requests go through a proxy server, by using the following environment variables:
|
|
132
|
-
|
|
133
|
-
- HTTP_PROXY_HOST and HTTP_PROXY_PORT control how http:// requests are sent
|
|
134
|
-
- HTTPS_PROXY_HOST and HTTPS_PROXY_PORT control how https:// requests are sent
|
|
135
|
-
|
|
136
|
-
## License
|
|
137
|
-
|
|
1
|
+
# OpenID for Node.js
|
|
2
|
+
|
|
3
|
+
OpenID for Node.js is (yes, you guessed it) an OpenID implementation for Node.js.
|
|
4
|
+
|
|
5
|
+
Highlights and features include:
|
|
6
|
+
|
|
7
|
+
- Full OpenID 1.0/1.1/2.0 compliant Relying Party (client) implementation
|
|
8
|
+
- Very simple API
|
|
9
|
+
- Simple extension points for association state
|
|
10
|
+
|
|
11
|
+
## Download
|
|
12
|
+
|
|
13
|
+
The library can be [reviewed and retrieved from GitHub](http://github.com/havard/node-openid).
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
If you use [`npm`](http://npmjs.org), simply do `npm install openid`.
|
|
18
|
+
|
|
19
|
+
Otherwise, you can grab the code from [GitHub](https://github.com/havard/node-openid).
|
|
20
|
+
|
|
21
|
+
## Examples
|
|
22
|
+
|
|
23
|
+
Here's a very simple server using OpenID for Node.js for authentication:
|
|
24
|
+
|
|
25
|
+
```javascript
|
|
26
|
+
var openid = require('openid');
|
|
27
|
+
var url = require('url');
|
|
28
|
+
var querystring = require('querystring');
|
|
29
|
+
var relyingParty = new openid.RelyingParty(
|
|
30
|
+
'http://example.com/verify', // Verification URL (yours)
|
|
31
|
+
null, // Realm (optional, specifies realm for OpenID authentication)
|
|
32
|
+
false, // Use stateless verification
|
|
33
|
+
false, // Strict mode
|
|
34
|
+
[]); // List of extensions to enable and include
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
var server = require('http').createServer(
|
|
38
|
+
function(req, res)
|
|
39
|
+
{
|
|
40
|
+
var parsedUrl = url.parse(req.url);
|
|
41
|
+
if(parsedUrl.pathname == '/authenticate')
|
|
42
|
+
{
|
|
43
|
+
// User supplied identifier
|
|
44
|
+
var query = querystring.parse(parsedUrl.query);
|
|
45
|
+
var identifier = query.openid_identifier;
|
|
46
|
+
|
|
47
|
+
// Resolve identifier, associate, and build authentication URL
|
|
48
|
+
relyingParty.authenticate(identifier, false, function(error, authUrl)
|
|
49
|
+
{
|
|
50
|
+
if (error)
|
|
51
|
+
{
|
|
52
|
+
res.writeHead(200);
|
|
53
|
+
res.end('Authentication failed: ' + error.message);
|
|
54
|
+
}
|
|
55
|
+
else if (!authUrl)
|
|
56
|
+
{
|
|
57
|
+
res.writeHead(200);
|
|
58
|
+
res.end('Authentication failed');
|
|
59
|
+
}
|
|
60
|
+
else
|
|
61
|
+
{
|
|
62
|
+
res.writeHead(302, { Location: authUrl });
|
|
63
|
+
res.end();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else if(parsedUrl.pathname == '/verify')
|
|
68
|
+
{
|
|
69
|
+
// Verify identity assertion
|
|
70
|
+
// NOTE: Passing just the URL is also possible
|
|
71
|
+
relyingParty.verifyAssertion(req, function(error, result)
|
|
72
|
+
{
|
|
73
|
+
res.writeHead(200);
|
|
74
|
+
res.end(!error && result.authenticated
|
|
75
|
+
? 'Success :)'
|
|
76
|
+
: 'Failure :(');
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
else
|
|
80
|
+
{
|
|
81
|
+
// Deliver an OpenID form on all other URLs
|
|
82
|
+
res.writeHead(200);
|
|
83
|
+
res.end('<!DOCTYPE html><html><body>'
|
|
84
|
+
+ '<form method="get" action="/authenticate">'
|
|
85
|
+
+ '<p>Login using OpenID</p>'
|
|
86
|
+
+ '<input name="openid_identifier" />'
|
|
87
|
+
+ '<input type="submit" value="Login" />'
|
|
88
|
+
+ '</form></body></html>');
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
server.listen(80);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
A more elaborate example including extensions can be found in `sample.js` in the GitHub repository.
|
|
95
|
+
|
|
96
|
+
## Supported Extensions
|
|
97
|
+
This library comes with built-in support for the following OpenID extensions:
|
|
98
|
+
|
|
99
|
+
- The Simple Registration (SREG) 1.1 extension is implemented as `openid.SimpleRegistration`.
|
|
100
|
+
- The Attribute Exchange (AX) 1.0 extension is implemented as `openid.AttributeExchange`.
|
|
101
|
+
- The OAuth 1.0 extension is implemented as `openid.OAuthHybrid`.
|
|
102
|
+
- The User Interface 1.0 extension is implemented as `openid.UserInterface`.
|
|
103
|
+
- The Provider Authentication Policy Extension 1.0 (PAPE) is implemented as `openid.pape`.
|
|
104
|
+
|
|
105
|
+
## Storing association state
|
|
106
|
+
|
|
107
|
+
To provide a way to save/load association state, you need to mix-in two functions in
|
|
108
|
+
the `openid` module:
|
|
109
|
+
|
|
110
|
+
- `saveAssociation(provider, type, handle, secret, expiry_time_in_seconds, callback)` is called when a new association is established during authentication. The callback should be called with any error as its first argument (or `null` if no error occured).
|
|
111
|
+
- `loadAssociation(handle, callback)` is used to retrieve the association identified by `handle` when verification happens. The callback should be called with any error as its first argument (and `null` as the second argument), or an object with the keys `provider`, `type`, `secret` if the association was loaded successfully.
|
|
112
|
+
|
|
113
|
+
The `openid` module includes default implementations for these functions using a simple object to store the associations in-memory.
|
|
114
|
+
|
|
115
|
+
## Caching discovered information
|
|
116
|
+
|
|
117
|
+
The verification of a positive assertion (i.e. an authenticated user) can be sped up significantly by avoiding the need for additional provider discoveries when possible. In order to achieve, this speed-up, node-openid needs to cache its discovered providers. You can mix-in two functions to override the default cache, which is an in-memory cache utilizing a simple object store:
|
|
118
|
+
|
|
119
|
+
- `saveDiscoveredInformation(key, provider, callback)` is used when saving a discovered provider. The following behavior is required:
|
|
120
|
+
- The `key` parameter should be uses as a key for storing the provider - it will be used as the lookup key when loading the provider. (Currently, the key is either a claimed identifier or an OP-local identifier, depending on the OpenID context.)
|
|
121
|
+
- When saving fails for some reason, `callback(error)` is called with `error` being an error object specifying what failed.
|
|
122
|
+
- When saving succeeds, `callback(null)` is called.
|
|
123
|
+
|
|
124
|
+
- `loadDiscoveredInformation(key, callback)` is used to load any previously discovered information about the provider for an identifier. The following behavior is required:
|
|
125
|
+
- When no provider is found for the identifier, `callback(null, null)` is called (i.e. it is not an error to not have any data to return).
|
|
126
|
+
- When loading fails for some reason, `callback(error, null)` is called with `error` being an error string specifying why loading failed.
|
|
127
|
+
- When loading succeeds, `callback(null, provider)` is called with the exact provider object that was previously stored using `saveDiscoveredInformation`.
|
|
128
|
+
|
|
129
|
+
## Proxy Support
|
|
130
|
+
`node-openid` makes HTTP and HTTPS requests during authentication. You can have these
|
|
131
|
+
requests go through a proxy server, by using the following environment variables:
|
|
132
|
+
|
|
133
|
+
- HTTP_PROXY_HOST and HTTP_PROXY_PORT control how http:// requests are sent
|
|
134
|
+
- HTTPS_PROXY_HOST and HTTPS_PROXY_PORT control how https:// requests are sent
|
|
135
|
+
|
|
136
|
+
## License
|
|
137
|
+
|
|
138
138
|
OpenID for Node.js is licensed under the MIT license. See LICENSE for further details.
|
package/SECURITY.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
# Security Policy
|
|
2
|
-
|
|
3
|
-
## Reporting a Vulnerability
|
|
4
|
-
|
|
5
|
-
Please send an e-mail to havard.stranden at that mail domain provided by that search giant beginning with the letter after f in the alphabet.
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
## Reporting a Vulnerability
|
|
4
|
+
|
|
5
|
+
Please send an e-mail to havard.stranden at that mail domain provided by that search giant beginning with the letter after f in the alphabet.
|
package/http.js
CHANGED
|
@@ -1,58 +1,63 @@
|
|
|
1
|
-
/* OpenID for node.js
|
|
2
|
-
*
|
|
3
|
-
* http://ox.no/software/node-openid
|
|
4
|
-
* http://github.com/havard/node-openid
|
|
5
|
-
*
|
|
6
|
-
* Copyright (C) 2010 by Håvard Stranden
|
|
7
|
-
*
|
|
8
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
-
* in the Software without restriction, including without limitation the rights
|
|
11
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
-
* furnished to do so, subject to the following conditions:
|
|
14
|
-
*
|
|
15
|
-
* The above copyright notice and this permission notice shall be included in
|
|
16
|
-
* all copies or substantial portions of the Software.
|
|
17
|
-
*
|
|
18
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
-
*/
|
|
25
|
-
|
|
26
|
-
const axios = require('axios').default;
|
|
27
|
-
const stringify = require("qs").stringify;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
exports.get = (getUrl, params, callback, redirects) => {
|
|
31
|
-
axios.get(getUrl, {
|
|
32
|
-
maxRedirects: redirects || 5,
|
|
33
|
-
qs: params,
|
|
34
|
-
headers: {
|
|
35
|
-
'Accept': 'application/xrds+xml,text/html,text/plain,*/*;q=0.9'
|
|
36
|
-
},
|
|
37
|
-
transformResponse: a => a
|
|
38
|
-
}).then(result => {
|
|
39
|
-
callback(result.data, result.headers, result.status);
|
|
40
|
-
}).catch(err => {
|
|
41
|
-
callback(err);
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
exports.post = function (postUrl, data, callback, redirects) {
|
|
46
|
-
const options = {
|
|
47
|
-
method: "POST",
|
|
48
|
-
url: postUrl,
|
|
49
|
-
maxRedirects: redirects || 5,
|
|
50
|
-
data: stringify(data),
|
|
51
|
-
headers: {
|
|
52
|
-
'Content-Type': 'application/x-www-form-urlencoded'
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
axios(options).then(response =>
|
|
56
|
-
callback(response.data, response.headers, response.status)
|
|
57
|
-
).catch(err =>
|
|
58
|
-
|
|
1
|
+
/* OpenID for node.js
|
|
2
|
+
*
|
|
3
|
+
* http://ox.no/software/node-openid
|
|
4
|
+
* http://github.com/havard/node-openid
|
|
5
|
+
*
|
|
6
|
+
* Copyright (C) 2010 by Håvard Stranden
|
|
7
|
+
*
|
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
13
|
+
* furnished to do so, subject to the following conditions:
|
|
14
|
+
*
|
|
15
|
+
* The above copyright notice and this permission notice shall be included in
|
|
16
|
+
* all copies or substantial portions of the Software.
|
|
17
|
+
*
|
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
const axios = require('axios').default;
|
|
27
|
+
const stringify = require("qs").stringify;
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
exports.get = (getUrl, params, callback, redirects) => {
|
|
31
|
+
axios.get(getUrl, {
|
|
32
|
+
maxRedirects: redirects || 5,
|
|
33
|
+
qs: params,
|
|
34
|
+
headers: {
|
|
35
|
+
'Accept': 'application/xrds+xml,text/html,text/plain,*/*;q=0.9'
|
|
36
|
+
},
|
|
37
|
+
transformResponse: a => a
|
|
38
|
+
}).then(result => {
|
|
39
|
+
callback(result.data, result.headers, result.status);
|
|
40
|
+
}).catch(err => {
|
|
41
|
+
callback(err);
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.post = function (postUrl, data, callback, redirects) {
|
|
46
|
+
const options = {
|
|
47
|
+
method: "POST",
|
|
48
|
+
url: postUrl,
|
|
49
|
+
maxRedirects: redirects || 5,
|
|
50
|
+
data: stringify(data),
|
|
51
|
+
headers: {
|
|
52
|
+
'Content-Type': 'application/x-www-form-urlencoded'
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
axios(options).then(response =>
|
|
56
|
+
callback(response.data, response.headers, response.status)
|
|
57
|
+
).catch(err => {
|
|
58
|
+
if (err.response) {
|
|
59
|
+
callback(err.response.data, err.response.headers, err.response.status);
|
|
60
|
+
}
|
|
61
|
+
callback(err)
|
|
62
|
+
});
|
|
63
|
+
};
|