File tree Expand file tree Collapse file tree 4 files changed +11
-43
lines changed
Expand file tree Collapse file tree 4 files changed +11
-43
lines changed Original file line number Diff line number Diff line change @@ -350,11 +350,11 @@ class AccountManager {
350350 this . accountWebIdFor ( userData . username )
351351 }
352352
353- if ( ! userConfig . webId && ! userConfig . username ) {
354- throw new Error ( 'Username or web id is required' )
355- }
353+ if ( ! userConfig . username ) {
354+ if ( ! userConfig . webId ) {
355+ throw new Error ( 'Username or web id is required' )
356+ }
356357
357- if ( userConfig . webId && ! userConfig . username ) {
358358 userConfig . username = this . usernameFromWebId ( userConfig . webId )
359359 }
360360
@@ -393,14 +393,6 @@ class AccountManager {
393393 } )
394394 }
395395
396- externalAccount ( webId ) {
397- let webIdHostname = url . parse ( webId ) . hostname
398-
399- let serverHostname = this . host . hostname
400-
401- return ! webIdHostname . endsWith ( serverHostname )
402- }
403-
404396 /**
405397 * Generates an expiring one-time-use token for password reset purposes
406398 * (the user's Web ID is saved in the token service).
Original file line number Diff line number Diff line change @@ -312,7 +312,6 @@ class TlsAuthenticator extends Authenticator {
312312 ensureLocalUser ( webId ) {
313313 const serverUri = this . accountManager . host . serverUri
314314
315- // if (this.accountManager.externalAccount(webId)) {
316315 if ( domainMatches ( serverUri , webId ) ) {
317316 // This is a locally hosted Web ID
318317 return Promise . resolve ( this . accountManager . userAccountFrom ( { webId } ) )
@@ -321,16 +320,15 @@ class TlsAuthenticator extends Authenticator {
321320 debug ( `WebID URI ${ JSON . stringify ( webId ) } is not a local account, verifying preferred provider` )
322321
323322 return this . discoverProviderFor ( webId )
324- . then ( preferredProvider => {
325- debug ( `Preferred provider for ${ webId } is ${ preferredProvider } ` )
323+ . then ( authorizedProvider => {
324+ debug ( `Authorized provider for ${ webId } is ${ authorizedProvider } ` )
326325
327- if ( preferredProvider === serverUri ) { // everything checks out
326+ if ( authorizedProvider === serverUri ) { // everything checks out
328327 return this . accountManager . userAccountFrom ( { webId, username : webId , externalWebId : true } )
329328 }
330329
331- throw new Error ( `This server is not the preferred provider for Web ID ${ webId } ` )
330+ throw new Error ( `This server is not the authorized provider for Web ID ${ webId } ` )
332331 } )
333- // return Promise.reject(new Error('Cannot login: Selected Web ID is not hosted on this server'))
334332 }
335333}
336334
Original file line number Diff line number Diff line change @@ -455,26 +455,4 @@ describe('AccountManager', () => {
455455 } )
456456 } )
457457 } )
458-
459- describe ( 'externalAccount()' , ( ) => {
460- it ( 'should return true if account is a subdomain of the local server url' , ( ) => {
461- let options = { host }
462-
463- let accountManager = AccountManager . from ( options )
464-
465- let webId = 'https://alice.example.com/#me'
466-
467- expect ( accountManager . externalAccount ( webId ) ) . to . be . false ( )
468- } )
469-
470- it ( 'should return false if account does not match the local server url' , ( ) => {
471- let options = { host }
472-
473- let accountManager = AccountManager . from ( options )
474-
475- let webId = 'https://alice.databox.me/#me'
476-
477- expect ( accountManager . externalAccount ( webId ) ) . to . be . true ( )
478- } )
479- } )
480458} )
Original file line number Diff line number Diff line change @@ -134,7 +134,7 @@ describe('TlsAuthenticator', () => {
134134 } )
135135
136136 describe ( 'ensureLocalUser()' , ( ) => {
137- it ( 'should throw an error if external user and this server not the preferred provider' , done => {
137+ it ( 'should throw an error if external user and this server not the authorized provider' , done => {
138138 let tlsAuth = new TlsAuthenticator ( { accountManager } )
139139
140140 let externalWebId = 'https://alice.someothersite.com#me'
@@ -143,7 +143,7 @@ describe('TlsAuthenticator', () => {
143143
144144 tlsAuth . ensureLocalUser ( externalWebId )
145145 . catch ( err => {
146- expect ( err . message ) . to . match ( / T h i s s e r v e r i s n o t t h e p r e f e r r e d p r o v i d e r f o r W e b I D h t t p s : \/ \/ a l i c e .s o m e o t h e r s i t e .c o m # m e / )
146+ expect ( err . message ) . to . match ( / T h i s s e r v e r i s n o t t h e a u t h o r i z e d p r o v i d e r f o r W e b I D h t t p s : \/ \/ a l i c e .s o m e o t h e r s i t e .c o m # m e / )
147147 done ( )
148148 } )
149149 } )
@@ -160,7 +160,7 @@ describe('TlsAuthenticator', () => {
160160 } )
161161 } )
162162
163- it ( 'should return a user instance if external user and this server is preferred provider' , ( ) => {
163+ it ( 'should return a user instance if external user and this server is authorized provider' , ( ) => {
164164 let tlsAuth = new TlsAuthenticator ( { accountManager } )
165165
166166 let externalWebId = 'https://alice.someothersite.com#me'
You can’t perform that action at this time.
0 commit comments