@@ -65,15 +65,18 @@ class LoginConsentRequest {
6565 static obtainConsent ( consentRequest ) {
6666 let { opAuthRequest, clientId } = consentRequest
6767
68+ const parsedAppOrigin = url . parse ( consentRequest . opAuthRequest . params . redirect_uri )
69+ const appOrigin = `${ parsedAppOrigin . protocol } //${ parsedAppOrigin . host } `
70+
6871 // Consent for the local RP client (the home pod) is implied
69- if ( consentRequest . isLocalRpClient ( consentRequest ) ) {
72+ if ( consentRequest . isLocalRpClient ( appOrigin ) ) {
7073 return Promise . resolve ( )
7174 . then ( ( ) => { consentRequest . markConsentSuccess ( opAuthRequest ) } )
7275 . then ( ( ) => opAuthRequest )
7376 }
7477
7578 // Check if user has submitted this from a Consent page
76- if ( consentRequest . params . consent ) {
79+ if ( consentRequest . hasAlreadyConsented ( appOrigin ) ) {
7780 return consentRequest . saveConsentForClient ( clientId )
7881 . then ( ( ) => { consentRequest . markConsentSuccess ( opAuthRequest ) } )
7982 . then ( ( ) => opAuthRequest )
@@ -98,10 +101,13 @@ class LoginConsentRequest {
98101 return this . params [ 'client_id' ]
99102 }
100103
101- isLocalRpClient ( request ) {
102- const parsedAppOrigin = url . parse ( request . opAuthRequest . params . redirect_uri )
103- const appOrigin = `${ parsedAppOrigin . protocol } //${ parsedAppOrigin . host } `
104- return request . opAuthRequest . req . app . locals . ldp . serverUri === appOrigin
104+ isLocalRpClient ( appOrigin ) {
105+ return this . opAuthRequest . req . app . locals . ldp . serverUri === appOrigin
106+ }
107+
108+ hasAlreadyConsented ( appOrigin ) {
109+ return this . opAuthRequest . req . session . consentedOrigins &&
110+ this . opAuthRequest . req . session . consentedOrigins . includes ( appOrigin )
105111 }
106112
107113 checkSavedConsentFor ( opAuthRequest ) {
@@ -121,15 +127,15 @@ class LoginConsentRequest {
121127 let { opAuthRequest } = this
122128 let consentUrl = url . parse ( '/consent' )
123129 consentUrl . query = opAuthRequest . req . query
124-
130+
125131 consentUrl = url . format ( consentUrl )
126132 opAuthRequest . subject = null
127-
133+
128134 opAuthRequest . res . redirect ( consentUrl )
129-
135+
130136 this . signalResponseSent ( )
131137 }
132-
138+
133139 signalResponseSent ( ) {
134140 throw new AuthResponseSent ( 'User redirected to login' )
135141 }
0 commit comments