1
- import {
2
- Authorizer , createErrorMessage , ForbiddenHttpError , getLoggerFor , UnauthorizedHttpError
1
+ import {
2
+ Authorizer , createErrorMessage , ForbiddenHttpError , getLoggerFor , InternalServerError , UnauthorizedHttpError
3
3
} from '@solid/community-server' ;
4
4
import type { AccessMap , AuthorizerInput } from '@solid/community-server' ;
5
5
import { OwnerUtil } from '../util/OwnerUtil' ;
@@ -30,25 +30,25 @@ export class UmaAuthorizer extends Authorizer {
30
30
*/
31
31
public constructor (
32
32
protected authorizer : Authorizer ,
33
- protected ownerUtil : OwnerUtil ,
33
+ protected ownerUtil : OwnerUtil ,
34
34
protected umaClient : UmaClient ,
35
35
) {
36
36
super ( ) ;
37
37
}
38
38
39
39
public async handle ( input : AuthorizerInput ) : Promise < void > {
40
40
try {
41
-
41
+
42
42
// Try authorizer
43
43
await this . authorizer . handleSafe ( input ) ;
44
44
} catch ( error : unknown ) {
45
45
46
46
// Unless 403/403 throw original error
47
47
if ( ! UnauthorizedHttpError . isInstance ( error ) && ! ForbiddenHttpError . isInstance ( error ) ) throw error ;
48
-
48
+
49
49
// Request UMA ticket
50
50
const authHeader = await this . requestTicket ( input . requestedModes ) ;
51
-
51
+
52
52
// Add auth header to error metadata if private
53
53
if ( authHeader ) {
54
54
error . metadata . add ( WWW_AUTH , literal ( authHeader ) ) ;
@@ -65,14 +65,14 @@ export class UmaAuthorizer extends Authorizer {
65
65
const owner = await this . ownerUtil . findCommonOwner ( requestedModes . keys ( ) ) ;
66
66
const issuer = await this . ownerUtil . findIssuer ( owner ) ;
67
67
68
- if ( ! issuer ) throw new Error ( `No UMA authorization server found for ${ owner } .` ) ;
68
+ if ( ! issuer ) throw new InternalServerError ( `No UMA authorization server found for ${ owner } .` ) ;
69
69
70
70
try {
71
71
const ticket = await this . umaClient . fetchTicket ( requestedModes , issuer ) ;
72
72
return ticket ? `UMA realm="solid", as_uri="${ issuer } ", ticket="${ ticket } "` : undefined ;
73
73
} catch ( e ) {
74
74
this . logger . error ( `Error while requesting UMA header: ${ ( e as Error ) . message } ` ) ;
75
- throw new Error ( ' Error while requesting UMA header.' ) ;
75
+ throw new InternalServerError ( ` Error while requesting UMA header: ${ ( e as Error ) . message } .` ) ;
76
76
}
77
77
}
78
78
}
0 commit comments