-
Notifications
You must be signed in to change notification settings - Fork 3
/
emby-auth.js
220 lines (204 loc) · 10.5 KB
/
emby-auth.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
function renderAuths() {
return {
wrapComponents: {
auths: (OriginalComponent, system) => (props) => {
const { definitions, getComponent, authSelectors, errSelectors } = props;
const AuthItem = getComponent('AuthItem');
const Oauth2 = getComponent('oauth2', true);
const Button = getComponent('Button');
const authorized = authSelectors.authorized();
const authorizedAuth = definitions.filter((definition, key) => {
return !!authorized.get(key);
});
const nonOauthDefinitions = definitions.filter(
schema => schema.get('type') !== 'oauth2'
);
const oauthDefinitions = definitions.filter(
schema => schema.get('type') === 'oauth2'
);
const httpSchemaDefinitions = definitions.filter(
schema => schema.get('type') === 'http'
);
return system.React.createElement('div', { className: 'auth-container' },
!!nonOauthDefinitions.size
&& system.React.createElement('form', { onSubmit: OriginalComponent.submitAuth },
nonOauthDefinitions.map((schema, name) => {
return system.React.createElement(AuthItem, {
key: name,
schema: schema,
name: name,
getComponent: getComponent,
onAuthChange: OriginalComponent.onAuthChange,
authorized: authorized,
errSelectors: errSelectors
});
})
.toArray(),
!httpSchemaDefinitions.size && system.React.createElement('div', { className: 'auth-btn-wrapper' },
nonOauthDefinitions.size === authorizedAuth.size
? system.React.createElement(Button,
{
className: 'btn modal-btn auth',
onClick: OriginalComponent.logoutClick
},
'Logout'
)
: system.React.createElement(Button,
{ type: 'submit', className: 'btn modal-btn auth authorize' },
'Authorize'
),
system.React.createElement(Button,
{ className: 'btn modal-btn auth btn-done', onClick: OriginalComponent.close },
'Close'
)
)
),
oauthDefinitions && oauthDefinitions.size
? system.React.createElement('div', null,
system.React.createElement('div', { className: 'scope-def' },
system.React.createElement('p', null,
'Scopes are used to grant an application different levels of access to data on behalf of the end user. Each API may declare one or more scopes.'
),
system.React.createElement('p', null,
'API requires the following scopes. Select which ones you want to grant to Swagger UI.'
)
),
definitions
.filter(schema => schema.get('type') === 'oauth2')
.map((schema, name) => {
return system.React.createElement('div',
{ key: name },
system.React.createElement(Oauth2, {
authorized: authorized,
schema: schema,
name: name
})
);
})
.toArray()
)
: null
);
}
}
};
};
function renderHttpAuth() {
return {
wrapComponents: {
HttpAuth: (OriginalComponent, system) => (props) => {
let { schema, getComponent, errSelectors, name } = props;
const Input = getComponent('Input');
const Row = getComponent('Row');
const Col = getComponent('Col');
const AuthError = getComponent('authError');
const Markdown = getComponent('Markdown');
const JumpToPath = getComponent('JumpToPath', true);
const scheme = (schema.get('scheme') || '').toLowerCase();
let value = null; // props.getValue();
let errors = errSelectors
.allErrors()
.filter(err => err.get('authId') === name);
if (scheme === 'basic') {
let username = value ? value.get('username') : null;
return system.React.createElement('div', null,
system.React.createElement('h4', null, system.React.createElement('code', null, name || schema.get('name')),
'\xA0 (http, Basic)',
system.React.createElement(JumpToPath,
{
path: ['securityDefinitions', name]
})
),
username && system.React.createElement('h6', null, 'Authorized'),
system.React.createElement(Row, null,
system.React.createElement(Markdown, { source: schema.get('description') })
),
system.React.createElement(Row, null,
system.React.createElement('label', null, 'Username:'),
username
? system.React.createElement('code', null, ' ', username, ' ')
: system.React.createElement(Col, null,
system.React.createElement(Input,
{
type: 'text',
required: 'required',
name: 'username',
onChange: onChange
})
)
),
system.React.createElement(Row, null,
system.React.createElement('label', null, 'Password:'),
username
? system.React.createElement('code', null, ' ****** ')
: system.React.createElement(Col, null,
system.React.createElement(Input,
{
required: 'required',
autoComplete: 'new-password',
name: 'password',
type: 'password',
onChange: onChange
})
)
),
errors.valueSeq().map((error, key) => {
return system.React.createElement(AuthError,
{
error: error,
key: key
});
})
);
}
if (scheme === 'bearer') {
return system.React.createElement('div', null,
system.React.createElement('h4', null,
system.React.createElement('code', null, name || schema.get('name')),
'\xA0 (http, Emby)',
system.React.createElement(JumpToPath,
{
path: ['securityDefinitions', name]
})
),
value && system.React.createElement('h6', null, 'Authorized'),
//system.React.createElement(Row, null,
// system.React.createElement('p', null, 'Authorize-Format: ',
// system.React.createElement('span', null, schema.get('bearerFormat')))
//),
system.React.createElement(Row, null,
system.React.createElement(Markdown, { source: schema.get('description') })
),
//system.React.createElement(Row, null,
// system.React.createElement('label', null, 'Value:'),
// value
// ? system.React.createElement('code', null, ' ****** ')
// : system.React.createElement(Col, null,
// system.React.createElement(Input,
// {
// type: 'text',
// onChange: onChange
// })
// )
//),
errors.valueSeq().map((error, key) => {
return system.React.createElement(AuthError,
{
error: error,
key: key
});
})
);
}
return system.React.createElement('div', null,
system.React.createElement('em', null,
system.React.createElement('b', null, name),
' HTTP authentication: unsupported scheme ',
`'${scheme}'`
)
);
}
}
};
};