@@ -2,89 +2,66 @@ import Log from './Log';
22import UrlUtility from './UrlUtility' ;
33import State from './State' ;
44
5- const OidcOptionalRequestParams = [ "prompt" , "display" , "max_age" , "ui_locales" , "id_token_hint" , "login_hint" , "acr_values" ] ;
6-
75export default class SigninRequest {
86 constructor ( {
7+ // mandatory
98 url, client_id, redirect_uri, response_type, scope, data,
9+ // optional
1010 prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values
1111 } ) {
12-
13- if ( ! url ) {
12+ if ( ! url ) {
1413 Log . error ( "No url passed to SigninRequest" ) ;
1514 throw new Error ( "url" ) ;
1615 }
17- if ( ! client_id ) {
16+ if ( ! client_id ) {
1817 Log . error ( "No client_id passed to SigninRequest" ) ;
1918 throw new Error ( "client_id" ) ;
2019 }
21- if ( ! redirect_uri ) {
20+ if ( ! redirect_uri ) {
2221 Log . error ( "No redirect_uri passed to SigninRequest" ) ;
2322 throw new Error ( "redirect_uri" ) ;
2423 }
25- if ( ! response_type ) {
24+ if ( ! response_type ) {
2625 Log . error ( "No response_type passed to SigninRequest" ) ;
2726 throw new Error ( "response_type" ) ;
2827 }
29- if ( ! scope ) {
28+ if ( ! scope ) {
3029 Log . error ( "No scope passed to SigninRequest" ) ;
3130 throw new Error ( "scope" ) ;
3231 }
32+
33+ let oidc = SigninRequest . isOidc ( response_type ) ;
34+ this . state = new State ( { nonce : oidc , data } ) ;
35+
36+ url = UrlUtility . addQueryParam ( url , "client_id" , client_id ) ;
37+ url = UrlUtility . addQueryParam ( url , "redirect_uri" , redirect_uri ) ;
38+ url = UrlUtility . addQueryParam ( url , "response_type" , response_type ) ;
39+ url = UrlUtility . addQueryParam ( url , "scope" , scope ) ;
3340
34- this . _url = url ;
35- this . _client_id = client_id ;
36- this . _redirect_uri = redirect_uri ;
37- this . _response_type = response_type ;
38- this . _scope = scope ;
39- this . _state = new State ( { nonce :this . isOidc , data} ) ;
40-
41- // optional
42- this . _prompt = prompt ;
43- this . _display = display ;
44- this . _max_age = max_age ;
45- this . _ui_locales = ui_locales ;
46- this . _id_token_hint = id_token_hint ;
47- this . _login_hint = login_hint ;
48- this . _acr_values = acr_values ;
49- }
50-
51- get state ( ) {
52- return this . _state ;
53- }
54-
55- get signinUrl ( ) {
56- if ( ! this . _signinUrl ) {
57- this . _signinUrl = this . _url ;
58-
59- this . _signinUrl = UrlUtility . addQueryParam ( this . _signinUrl , "client_id" , this . _client_id ) ;
60- this . _signinUrl = UrlUtility . addQueryParam ( this . _signinUrl , "redirect_uri" , this . _redirect_uri ) ;
61- this . _signinUrl = UrlUtility . addQueryParam ( this . _signinUrl , "response_type" , this . _response_type ) ;
62- this . _signinUrl = UrlUtility . addQueryParam ( this . _signinUrl , "scope" , this . _scope ) ;
63- this . _signinUrl = UrlUtility . addQueryParam ( this . _signinUrl , "state" , this . _state . id ) ;
64-
65- if ( this . isOidc ) {
66- this . _signinUrl = UrlUtility . addQueryParam ( this . _signinUrl , "nonce" , this . _state . nonce ) ;
41+ url = UrlUtility . addQueryParam ( url , "state" , this . state . id ) ;
42+ if ( oidc ) {
43+ url = UrlUtility . addQueryParam ( url , "nonce" , this . state . nonce ) ;
44+ }
45+
46+ var optional = { prompt, display, max_age, ui_locales, id_token_hint, login_hint, acr_values } ;
47+ for ( let key in optional ) {
48+ if ( optional [ key ] ) {
49+ url = UrlUtility . addQueryParam ( url , key , optional [ key ] ) ;
6750 }
68-
69- OidcOptionalRequestParams . forEach ( key => {
70- if ( this [ "_" + key ] ) {
71- this . _signinUrl = UrlUtility . addQueryParam ( this . _signinUrl , key , this [ "_" + key ] ) ;
72- }
73- } ) ;
7451 }
75-
76- return this . _signinUrl ;
52+
53+ this . url = url ;
7754 }
7855
79- get isOidc ( ) {
80- var result = this . _response_type . split ( / \s + / g) . filter ( function ( item ) {
56+ static isOidc ( response_type ) {
57+ var result = response_type . split ( / \s + / g) . filter ( function ( item ) {
8158 return item === "id_token" ;
8259 } ) ;
8360 return ! ! ( result [ 0 ] ) ;
8461 }
85-
86- get isOAuth ( ) {
87- var result = this . _response_type . split ( / \s + / g) . filter ( function ( item ) {
62+
63+ static isOAuth ( response_type ) {
64+ var result = response_type . split ( / \s + / g) . filter ( function ( item ) {
8865 return item === "token" ;
8966 } ) ;
9067 return ! ! ( result [ 0 ] ) ;
0 commit comments