UNPKG

4.15 kBJavaScriptView Raw
1import AmpState from 'ampersand-state';
2
3// The credentials config which includes the CI server info and derived
4// URL properties from them for the various CI services. The URL's
5// will be updated when the CI changes.
6const CredentialsConfig = AmpState.extend({
7
8 // we need to allow extra props for dynamic props like jwtRefreshCallback
9 extraProperties: 'allow',
10
11 props: {
12 /**
13 * The idbroker base host name
14 * @returns {object}
15 */
16 idbroker: ['object', false, (() => ({
17 url: process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'
18 }))],
19
20 /**
21 * The identity base host name
22 * @returns {object}
23 */
24 identity: ['object', false, (() => ({
25 url: process.env.IDENTITY_BASE_URL || 'https://identity.webex.com'
26 }))],
27
28 /**
29 * This is the authorization url displayed on the
30 * {@link developer portal|https://developer.webex.com}
31 * @type {string}
32 */
33 authorizationString: ['string', false, process.env.WEBEX_AUTHORIZATION_STRING || process.env.AUTHORIZATION_STRING],
34
35 /**
36 * Authorization URL which prompts for user's password. Inferred from
37 * {@link config.credentials.authorizationString}. This config value will
38 * be automatically set if `authorizationString` config value is specified.
39 *
40 * @type {string}
41 */
42 authorizeUrl: [
43 'string',
44 false,
45 process.env.WEBEX_AUTHORIZE_URL ||
46 `${process.env.IDBROKER_BASE_URL || 'https://idbroker.webex.com'}/idb/oauth2/v1/authorize`
47 ],
48
49 /**
50 * {@see https://tools.ietf.org/html/rfc6749#section-4.1.4}
51 * @type {string}
52 */
53 client_id: ['string', false, process.env.WEBEX_CLIENT_ID || process.env.COMMON_IDENTITY_CLIENT_ID || process.env.CLIENT_ID],
54
55 /**
56 * {@see https://tools.ietf.org/html/rfc6749#section-4.1.4}
57 * @type {string}
58 */
59 client_secret: ['string', false, process.env.WEBEX_CLIENT_SECRET || process.env.COMMON_IDENTITY_CLIENT_SECRET || process.env.CLIENT_SECRET],
60
61 /**
62 * {@see https://tools.ietf.org/html/rfc6749#section-4.1.4}
63 * @type {string}
64 */
65 redirect_uri: ['string', false, process.env.WEBEX_REDIRECT_URI || process.env.COMMON_IDENTITY_REDIRECT_URI || process.env.REDIRECT_URI],
66
67 /**
68 * {@see https://tools.ietf.org/html/rfc6749#section-4.1.4}
69 * @type {string}
70 */
71 scope: ['string', false, process.env.WEBEX_SCOPE || process.env.WEBEX_SCOPES || process.env.COMMON_IDENTITY_SCOPE || process.env.SCOPE],
72
73 /**
74 * Controls the UI of the CI login page.
75 * @private
76 * @type {string}
77 */
78 cisService: ['string', false, 'webex']
79 },
80
81 derived: {
82 /**
83 * User activation URL
84 * {@link config.credentials.activationUrl}
85 * @type {string}
86 */
87 activationUrl: {
88 deps: ['idbroker.url'],
89 fn() {
90 return `${this.idbroker.url || 'https://idbroker.webex.com'}/idb/token/v1/actions/UserActivation/invoke`;
91 },
92 cache: false
93 },
94
95 // TODO does hydra also have an access_token endpoint?
96 /**
97 * Token URL used for token refresh and auth code exchange
98 * @type {string}
99 */
100 tokenUrl: {
101 deps: ['idbroker.url'],
102 fn() {
103 return process.env.TOKEN_URL || `${this.idbroker.url}/idb/oauth2/v1/access_token`;
104 },
105 cache: false
106 },
107
108 /**
109 * URL to revoke token
110 * @type {string}
111 */
112 revokeUrl: {
113 deps: ['idbroker.url'],
114 fn() {
115 return process.env.REVOKE_URL || `${this.idbroker.url}/idb/oauth2/v1/revoke`;
116 },
117 cache: false
118 },
119
120 /**
121 * URL to load when the app logs out
122 * @type {string}
123 */
124 logoutUrl: {
125 deps: ['idbroker.url'],
126 fn() {
127 return `${this.idbroker.url}/idb/oauth2/v1/logout`;
128 },
129 cache: false
130 },
131
132 /**
133 * Set password URL
134 * @type {string}
135 */
136 setPasswordUrl: {
137 deps: ['identity.url'],
138 fn() {
139 return `${this.identity.url || 'https://identity.webex.com'}/identity/scim/v1/Users`;
140 },
141 cache: false
142 }
143
144 }
145
146});
147
148export default CredentialsConfig;