This repository has been archived by the owner on Nov 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsecurity.interface.ts
333 lines (325 loc) · 7.23 KB
/
security.interface.ts
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
//#region Security config
/**
* Security config
*/
interface ISecurityConfig extends IBaseConfig {
/**
* Storage name of token
*/
tokenStorageName: string;
/**
* Session storage name of temprorary data
*/
stateTempStorageName: string;
/**
* Redirecting uri for unauthorized requests
*/
redirectUri: string;
/**
* Default uri to redirect after successful authorization
*/
postLogoutRedirectUri: string;
/**
* Response type for OIC
*/
responseType: string;
/**
* Default scopes
*/
scope: string;
/**
* Flag that indicates if user-profile-endpoint will be used for profile information
*/
loadUserProfile: boolean;
/**
* Flag that if omitting built-it claims is active
*/
filterProtocolClaims: boolean;
/**
* Client Id
*/
clientId: string;
/**
* OIC main uri
*/
authority: string;
/**
* Flag that if app will be used with no authoirzation or not
*/
allowAnonymousAccess: boolean;
/**
* Auhorized Companies
*/
authorizedCompanies?: ICompany[];
/**
* Default company Id
*/
defaultCompanyId?: number;
/**
* User profile fetched from server to combine with currentUser:IUser
*/
userProfile?: any;
/**
* User picture upload uri
*/
avatarUploadUri?: string;
/**
* Avatar get uri,User id will be added as parameter
*/
avatarUri?: string;
/**
* Flag that indicates if AntiForgerytoken is enabled
*/
antiForgeryTokenEnabled?: boolean;
/**
* Backend url for antiforgery token
*/
antiForgeryTokenUrl?: string;
/**
* Antiforgerytoken request header name
*/
antiForgeryTokenHeaderName?: string;
}
/**
* Security config provider
*/
interface ISecurityConfigProvider extends IBaseConfigProvider<ISecurityConfig> {
}
//#endregion
//#region Security Service
/**
* Security service
*/
interface ISecurity extends IBaseService {
/**
* Current principal
*/
currentUser: IUser;
/**
* Current company
*/
currentCompany: ICompany;
/**
* Security config
*/
securityConfig: ISecurityConfig;
/**
* Promise initiated at run phase
*/
initPromise: ng.IPromise<IProfileModel<IUser> | string>;
/**
* Authorization flag
*/
isAuthenticated: boolean;
/**
* Initialize security
* @returns {IProfileModel<IUser>}
*/
initSecurity(): ng.IPromise<IProfileModel<IUser> | string>;
/**
* Used by routing service to show view
* @param state State obj
* @description if promise resolved,state is authenticated
* @returns {ng.IPromise<any>}
*/
isStateAuthenticated(state: IRotaState): ng.IPromise<any>;
/**
* Logoff
* @returns {ng.IPromise<any>}
*/
logOff(): ng.IPromise<any>;
/**
* Request token from which defined in security config
* @returns {}
*/
getAntiForgeryToken(state: IRotaState): ng.IPromise<string>;
}
//#endregion
//#region Claims & User
/**
* Base User profile
*/
interface IUser {
fullname: string;
name: string;
email?: string;
managerId?: number;
languageid?: number;
id: number;
}
/**
* All claims
*/
interface IClaims {
[index: string]: string;
}
/**
* Company structure
*/
interface ICompany {
/**
* Unique identifier,not company's real id
* Will be used for storing current company
*/
id: number;
companyName: string;
/**
* This props is added to request header
*/
companyId?: number;
roleId?: number;
}
//#endregion
//#region OpenId Configuration
/**
* OIC metadata
*/
interface IOpenIdMetaData extends IBaseServerResponseData {
issuer: string;
jwks_uri: string;
authorization_endpoint: string;
token_endpoint: string;
userinfo_endpoint: string;
end_session_endpoint: string;
check_session_iframe: string;
revocation_endpoint: string;
introspection_endpoint: string;
http_logout_supported: boolean;
scopes_supported: Array<string>;
claims_supported: Array<string>;
response_types_supported: Array<string>;
response_modes_supported: Array<string>;
grant_types_supported: Array<string>;
subject_types_supported: Array<string>;
id_token_signing_alg_values_supported: Array<string>;
token_endpoint_auth_methods_supported: Array<string>;
}
/**
* Keys
*/
interface IJwk {
kty: string;
use: string;
kid: string;
x5t: string;
e: string;
n: string;
x5c: Array<string>;
}
/**
* JSON web keys
*/
interface IJwks extends IBaseServerResponseData {
keys: Array<IJwk>;
}
//#endregion
//#region JWT Service
/**
* JWT helper service
*/
interface IJWTHelper {
/**
* Shortcut way of rejection promise
* @param cause Reason
* @returns {ng.IPromise<string>}
*/
reject(cause?: string): ng.IPromise<string>;
/**
* Load metadata information using authority
* @returns {ng.IPromise<IOpenIdMetaData>}
*/
loadMetadata(): ng.IPromise<IOpenIdMetaData | string>;
/**
* Gets authorization endpoint uri using metadata
* @returns {ng.IPromise<string>}
*/
loadAuthorizationEndpoint(): ng.IPromise<string>;
/**
* Load user profile using profile end point in case loadUserProfile flag is true
* @param accessToken Access Token
* @returns {ng.IPromise<IUser>}
*/
loadUserProfile(accessToken: string): ng.IPromise<IUser | string>;
/**
* Create Logout request using metadata
* @param idTokenHint Id Token
* @returns {ng.IPromise<string>}
*/
createLogoutRequest(idTokenHint: string): ng.IPromise<string>;
/**
* Get signing key using metadata
* @returns {ng.IPromise<string>}
*/
loadX509SigningKey(): ng.IPromise<string>;
/**
* Validate Id Token comparing state,nonce etc..
* @param idToken Id Token
* @param nonce Nonce - Number once
* @returns {ng.IPromise<IClaims>}
*/
validateIdToken(idToken: string, nonce: string): ng.IPromise<IClaims | string>;
/**
* Filters claims using openIdBuiltInClaims
* @param claims All Claims
* @returns {IUser}
*/
filterProtocolClaims(claims: any): IUser;
}
//#endregion
//#region Token Interfaces
/**
* Temprorary session data
*/
interface ITempSessionData {
nonce: string;
state: string;
}
/**
* Token model returned from OIC
*/
interface ITokenModel {
id_token?: string;
access_token?: string;
token_type: string;
expires_in: number;
scope?: string;
state?: string;
session_state?: string;
}
/**
* Used for generation request uri for OIC
*/
interface ITokenRequest {
settings: ITempSessionData;
url: string;
}
/**
* Structure to be stored including profile information and tokens
*/
interface IProfileModel<T extends IUser> {
/**
* User profile
*/
profile: T,
/**
* Id Token
*/
id_token?: string;
/**
* Access Token
*/
access_token?: string;
/**
* Time span for expiration
*/
expires_in: number;
}
/**
* Token service structure
*/
interface ITokens {
idToken: string;
accessToken: string;
antiForgeryToken?: string;
}
//#endregion