@@ -10,6 +10,52 @@ class MultiRpClient {
1010 this . debug = options . debug || console . log . bind ( console )
1111 }
1212
13+ /**
14+ * Returns the authorization (signin) URL for a given OIDC client (which
15+ * is tied to / registered with a specific OIDC Provider).
16+ * @method authUrl
17+ * @param expressClient {OIDCExpressClient}
18+ * @param workflow {string} OIDC workflow type, one of 'code' or 'implicit'.
19+ * @return {string } Absolute URL for an OIDC auth call (to start either
20+ * the Authorization Code workflow, or the Implicit workflow).
21+ */
22+ authUrl ( expressClient , workflow = 'code' ) {
23+ let debug = this . debug
24+ let authParams = {
25+ endpoint : 'signin' ,
26+ response_mode : 'query' ,
27+ // response_mode: 'form_post',
28+ client_id : expressClient . client . client_id ,
29+ redirect_uri : expressClient . client . redirect_uri ,
30+ // state: '...', // not doing state for the moment
31+ scope : 'openid profile' // not doing 'openid profile' for the moment
32+ }
33+ if ( workflow === 'code' ) { // Authorization Code workflow
34+ authParams . response_type = 'code'
35+ } else if ( workflow === 'implicit' ) {
36+ authParams . response_type = 'id_token token'
37+ authParams . nonce = '123' // TODO: Implement proper nonce generation
38+ }
39+
40+ var signinUrl = expressClient . client . authorizationUri ( authParams )
41+ debug ( 'Signin url: ' + signinUrl )
42+ return signinUrl
43+ }
44+
45+ /**
46+ * Returns a constructed `/authorization` URL for a given issuer. Used for
47+ * starting the OIDC workflow.
48+ * @param issuer {string} OIDC Provider URL
49+ * @param workflow {string} OIDC workflow type, one of 'code' or 'implicit'
50+ * @returns {Promise<string> }
51+ */
52+ authUrlForIssuer ( issuer , workflow = 'code' ) {
53+ return this . clientForIssuer ( issuer )
54+ . then ( ( client ) => {
55+ return this . authUrl ( client , workflow )
56+ } )
57+ }
58+
1359 /**
1460 * @method clientForIssuer
1561 * @param issuerUri {string}
@@ -70,13 +116,13 @@ class MultiRpClient {
70116 registerClient ( config ) {
71117 let debug = this . debug
72118 let oidcExpress = new OIDCExpressClient ( config )
73- debug . oidc ( 'Running client.initProvider()...' )
119+ debug ( 'Running client.initProvider()...' )
74120 return oidcExpress . client . initProvider ( )
75121 . then ( ( ) => {
76- debug . oidc ( 'Client discovered, JWKs retrieved' )
122+ debug ( 'Client discovered, JWKs retrieved' )
77123 if ( ! oidcExpress . client . client_id ) {
78124 // Register if you haven't already.
79- debug . oidc ( 'Registering client' )
125+ debug ( 'Registering client' )
80126 return oidcExpress . client . register ( config )
81127 } else {
82128 // Already registered.
0 commit comments