@mapcreator/api 3.3.6 → 3.3.7
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/dist/Mapcreator.d.ts +6 -0
- package/dist/bundle.browser.js +438 -504
- package/dist/bundle.browser.min.js +1 -1
- package/dist/bundle.browser.min.js.LICENSE.txt +2 -2
- package/dist/bundle.js +446 -512
- package/dist/bundle.min.js +1 -1
- package/dist/bundle.min.js.LICENSE.txt +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/resources/DomainLoginMethod.d.ts +7 -0
- package/dist/resources/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/Mapcreator.js +11 -17
- package/src/index.js +0 -1
- package/src/resources/DomainLoginMethod.js +42 -0
- package/src/resources/index.js +1 -0
- package/src/oauth/CookieFlow.js +0 -103
package/src/oauth/CookieFlow.js
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* BSD 3-Clause License
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) 2020, Mapcreator
|
|
5
|
-
* All rights reserved.
|
|
6
|
-
*
|
|
7
|
-
* Redistribution and use in source and binary forms, with or without
|
|
8
|
-
* modification, are permitted provided that the following conditions are met:
|
|
9
|
-
*
|
|
10
|
-
* Redistributions of source code must retain the above copyright notice, this
|
|
11
|
-
* list of conditions and the following disclaimer.
|
|
12
|
-
*
|
|
13
|
-
* Redistributions in binary form must reproduce the above copyright notice,
|
|
14
|
-
* this list of conditions and the following disclaimer in the documentation
|
|
15
|
-
* and/or other materials provided with the distribution.
|
|
16
|
-
*
|
|
17
|
-
* Neither the name of the copyright holder nor the names of its
|
|
18
|
-
* contributors may be used to endorse or promote products derived from
|
|
19
|
-
* this software without specific prior written permission.
|
|
20
|
-
*
|
|
21
|
-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
22
|
-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
23
|
-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
24
|
-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
25
|
-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
26
|
-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
27
|
-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
28
|
-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
29
|
-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
30
|
-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
import OAuth from './OAuth';
|
|
34
|
-
import OAuthToken from './OAuthToken';
|
|
35
|
-
import { encodeQueryString } from '../utils/requests';
|
|
36
|
-
import { isNode } from '../utils/node';
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Cookie-based authentication flow using redirection
|
|
40
|
-
*/
|
|
41
|
-
export default class CookieFlow extends OAuth {
|
|
42
|
-
/**
|
|
43
|
-
* Cookie-based authentication flow
|
|
44
|
-
* @param {String} clientId - OAuth client id
|
|
45
|
-
* @param {String} callbackUrl - callbackUrl to redirect to after successful login
|
|
46
|
-
* @param {Array<String>} scopes - A list of required scopes
|
|
47
|
-
*/
|
|
48
|
-
constructor(clientId, callbackUrl = '', scopes = ['*']) {
|
|
49
|
-
super(clientId, scopes);
|
|
50
|
-
|
|
51
|
-
if (isNode()) {
|
|
52
|
-
throw new Error(`${this.constructor.name} can't be used under nodejs`);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
this.path = '/login';
|
|
56
|
-
this.callbackUrl = callbackUrl;
|
|
57
|
-
|
|
58
|
-
if (!this.callbackUrl) {
|
|
59
|
-
// Drop the anchor (if any)
|
|
60
|
-
this.callbackUrl = window.location.toString().split('#')[0];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @inheritDoc
|
|
66
|
-
*/
|
|
67
|
-
authenticate() {
|
|
68
|
-
return new Promise((resolve, reject) => {
|
|
69
|
-
// Check authentication status by making a request to the user resources endpoint
|
|
70
|
-
fetch(`${this.host}/v1/users/me/resources`, {
|
|
71
|
-
method: 'GET',
|
|
72
|
-
credentials: 'include', // Important: include cookies in the request
|
|
73
|
-
})
|
|
74
|
-
.then(response => {
|
|
75
|
-
if (response.ok) {
|
|
76
|
-
// We're authenticated, create a token object to maintain compatibility
|
|
77
|
-
this.token = new OAuthToken('cookie_auth', 'cookie', 86400);
|
|
78
|
-
resolve(this.token);
|
|
79
|
-
} else {
|
|
80
|
-
// Not authenticated, redirect to login
|
|
81
|
-
window.location = this._buildRedirectUrl();
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
.catch(error => {
|
|
85
|
-
// Network error or other issues, redirect to login
|
|
86
|
-
window.location = this._buildRedirectUrl();
|
|
87
|
-
});
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Builds the url for redirection
|
|
93
|
-
* @returns {String} - Redirect url
|
|
94
|
-
* @protected
|
|
95
|
-
*/
|
|
96
|
-
_buildRedirectUrl() {
|
|
97
|
-
const queryParams = {
|
|
98
|
-
'redirect_uri': this.callbackUrl,
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
return `${this.host + this.path}?${encodeQueryString(queryParams)}`;
|
|
102
|
-
}
|
|
103
|
-
}
|