@@ -41,7 +41,7 @@ class IDToken extends JWT {
4141 static issue ( provider , options ) {
4242 let { issuer, keys } = provider
4343
44- let { aud, azp, sub, nonce, at_hash, c_hash, cnf } = options
44+ let { aud, azp, sub, nonce, at_hash, c_hash, cnf, scope } = options
4545
4646 let alg = options . alg || DEFAULT_SIG_ALGORITHM
4747 let jti = options . jti || random ( 8 )
@@ -57,8 +57,8 @@ class IDToken extends JWT {
5757 let header = { alg, kid }
5858 let payload = { iss, aud, azp, sub, exp, iat, jti, nonce }
5959
60- // Add webid claim for Solid OIDC compliance
61- if ( sub ) {
60+ // Add webid claim for Solid OIDC compliance only if webid scope is requested
61+ if ( sub && scope && ( scope . includes ( 'webid' ) || scope . split ( ' ' ) . includes ( 'webid' ) ) ) {
6262 payload . webid = sub
6363 }
6464
@@ -80,23 +80,26 @@ class IDToken extends JWT {
8080 let alg = client [ 'id_token_signed_response_alg' ] || DEFAULT_SIG_ALGORITHM
8181 let jti = random ( 8 )
8282 let iat = Math . floor ( Date . now ( ) / 1000 )
83- let aud , azp , sub , max , nonce
83+ let aud , azp , sub , max , nonce , scope
8484
8585 // authentication request
8686 if ( ! code ) {
87- aud = client [ 'client_id' ]
87+ aud = [ client [ 'client_id' ] , 'solid ']
8888 azp = client [ 'client_id' ]
89- sub = subject [ '_id' ]
89+ // Use WebID URL for sub if available (Solid OIDC compliance), otherwise use database ID
90+ sub = subject ?. webId || subject [ '_id' ]
9091 max = parseInt ( params [ 'max_age' ] ) || client [ 'default_max_age' ] || DEFAULT_MAX_AGE
9192 nonce = params . nonce
93+ scope = params . scope // Get the requested scope
9294
9395 // token request
9496 } else {
95- aud = code . aud
96- azp = code . azp || aud
97+ aud = Array . isArray ( code . aud ) ? [ ... code . aud , 'solid' ] : [ code . aud , 'solid' ]
98+ azp = code . azp || ( Array . isArray ( code . aud ) ? code . aud [ 0 ] : code . aud )
9799 sub = code . sub
98100 max = parseInt ( code [ 'max' ] ) || client [ 'default_max_age' ] || DEFAULT_MAX_AGE
99101 nonce = code . nonce
102+ scope = code . scope // Get the scope from authorization code
100103 }
101104
102105 let len = alg . match ( / ( 2 5 6 | 3 8 4 | 5 1 2 ) $ / ) [ 0 ]
@@ -111,7 +114,7 @@ class IDToken extends JWT {
111114 . then ( hashes => {
112115 let [ at_hash , c_hash ] = hashes
113116
114- let options = { alg, aud, azp, sub, iat, jti, nonce, at_hash, c_hash }
117+ let options = { alg, aud, azp, sub, iat, jti, nonce, at_hash, c_hash, scope }
115118
116119 if ( request . cnfKey ) {
117120 options . cnf = { jwk : request . cnfKey }
0 commit comments