@@ -34,11 +34,11 @@ module.exports = class OidcRpClient {
3434 * is tied to / registered with a specific OIDC Provider).
3535 * @method authUrl
3636 * @param oidcClient {OIDCExpressClient}
37- * @param flowType {String} OIDC workflow type, one of 'code' or 'implicit'.
37+ * @param workflow {String} OIDC workflow type, one of 'code' or 'implicit'.
3838 * @return {String } Absolute URL for an OIDC auth call (to start either
3939 * the Authorization Code workflow, or the Implicit workflow).
4040 */
41- authUrl ( oidcClient , flowType = 'code' ) {
41+ authUrl ( oidcClient , workflow = 'code' ) {
4242 let authParams = {
4343 endpoint : 'signin' ,
4444 response_mode : 'query' ,
@@ -48,9 +48,9 @@ module.exports = class OidcRpClient {
4848 // state: '...', // not doing state for the moment
4949 scope : 'openid profile' // not doing 'openid profile' for the moment
5050 }
51- if ( flowType === 'code' ) { // Authorization Code workflow
51+ if ( workflow === 'code' ) { // Authorization Code workflow
5252 authParams . response_type = 'code'
53- } else if ( flowType === 'implicit' ) {
53+ } else if ( workflow === 'implicit' ) {
5454 authParams . response_type = 'id_token token'
5555 authParams . nonce = '123' // TODO: Implement proper nonce generation
5656 }
@@ -60,10 +60,17 @@ module.exports = class OidcRpClient {
6060 return signinUrl
6161 }
6262
63- authUrlForIssuer ( issuer ) {
63+ /**
64+ * Returns a constructed `/authorization` URL for a given issuer. Used for
65+ * starting the OIDC workflow.
66+ * @param issuer {String} OIDC Provider URL
67+ * @param workflow {String} OIDC workflow type, one of 'code' or 'implicit'
68+ * @returns {Promise }
69+ */
70+ authUrlForIssuer ( issuer , workflow = 'code' ) {
6471 return this . clientForIssuer ( issuer )
6572 . then ( ( client ) => {
66- return this . authUrl ( client , 'code' )
73+ return this . authUrl ( client , workflow )
6774 } )
6875 }
6976
@@ -146,6 +153,7 @@ module.exports = class OidcRpClient {
146153 * @param config.redirect_uri {String} Callback URL invoked by provider
147154 * @param config.client_id {String} Pre-registered trusted client id
148155 * @param config.client_secret {String} Pre-registered trusted client secret
156+ * @param config.post_logout_redirect_uris {Array<String>}
149157 * @return {Promise<OIDCExpressClient> }
150158 */
151159 ensureTrustedClient ( config ) {
@@ -169,6 +177,9 @@ module.exports = class OidcRpClient {
169177 return client
170178 } )
171179 } )
180+ . catch ( ( err ) => {
181+ debug . oidc ( 'Error initializing trusted client!' , err )
182+ } )
172183 }
173184
174185 /**
@@ -180,13 +191,15 @@ module.exports = class OidcRpClient {
180191 * @param config.redirect_uri {String}
181192 * @param [config.client_id] {String} Pre-registered trusted client id
182193 * @param [config.client_secret] {String} Pre-registered trusted client secret
194+ * @param [config.post_logout_redirect_uris] {Array<String>}
183195 * @return {Promise<OIDCExpressClient> } Initialized/registered api client
184196 */
185197 initClient ( config , isTrustedClient = false ) {
186198 var oidcExpress = new OIDCExpressClient ( config )
187199 // registration spec takes a list of redirect uris. just go with it..
188200 let redirectUris = [ config . redirect_uri ]
189- var registration = this . registrationConfig ( config . issuer , redirectUris )
201+ var registration = this . registrationConfig ( config . issuer , redirectUris ,
202+ config . post_logout_redirect_uris )
190203 debug . oidc ( 'Registration config: ' )
191204 debug . oidc ( registration )
192205 debug . oidc ( 'Running client.initProvider()...' )
@@ -197,6 +210,10 @@ module.exports = class OidcRpClient {
197210 // Register if you haven't already.
198211 debug . oidc ( 'Registering client' )
199212 return oidcExpress . client . register ( registration )
213+ } else {
214+ // Already registered.
215+ oidcExpress . client . registration = registration
216+ return oidcExpress
200217 }
201218 } )
202219 . then ( ( ) => {
@@ -226,9 +243,10 @@ module.exports = class OidcRpClient {
226243 * @param issuer {String} URL of the OIDC Provider / issuer.
227244 * @param redirectUris {Array<String>} List of allowed URIs to which the
228245 * provider will redirect users after login etc.
246+ * @param [postLogoutUris] {Array<String>}
229247 * @return {Object } OIDC Client registration config options
230248 */
231- registrationConfig ( issuer , redirectUris ) {
249+ registrationConfig ( issuer , redirectUris , postLogoutUris ) {
232250 let clientName = `Solid OIDC Client for ${ issuer } `
233251 let config = {
234252 client_name : clientName ,
@@ -245,6 +263,9 @@ module.exports = class OidcRpClient {
245263 response_types : [ 'code' , 'id_token token' , 'code id_token token' ] ,
246264 scope : 'openid profile'
247265 }
266+ if ( postLogoutUris ) {
267+ config . post_logout_redirect_uris = postLogoutUris
268+ }
248269 return config
249270 }
250271}
0 commit comments