6
6
7
7
package io .jans .as .server .service .external .context ;
8
8
9
+ import com .google .common .collect .Lists ;
9
10
import io .jans .as .common .model .registration .Client ;
10
11
import io .jans .as .common .service .AttributeService ;
11
12
import io .jans .as .model .common .GrantType ;
12
13
import io .jans .as .model .configuration .AppConfiguration ;
13
14
import io .jans .as .model .jwt .Jwt ;
15
+ import io .jans .as .model .jwt .JwtClaims ;
14
16
import io .jans .as .server .model .common .AccessToken ;
15
17
import io .jans .as .server .model .common .AuthorizationGrant ;
16
18
import io .jans .as .server .model .common .ExecutionContext ;
19
+ import io .jans .as .server .model .token .JwtSigner ;
17
20
import io .jans .model .custom .script .conf .CustomScriptConfiguration ;
18
- import org .jetbrains .annotations .Nullable ;
19
-
20
21
import jakarta .servlet .http .HttpServletRequest ;
22
+ import org .jetbrains .annotations .Nullable ;
21
23
import org .slf4j .Logger ;
22
24
import org .slf4j .LoggerFactory ;
23
25
@@ -39,6 +41,7 @@ public class ExternalUpdateTokenContext extends ExternalScriptContext {
39
41
private CustomScriptConfiguration script ;
40
42
@ Nullable
41
43
private ExecutionContext executionContext ;
44
+ private JwtSigner jwtSigner ;
42
45
43
46
public ExternalUpdateTokenContext (HttpServletRequest httpRequest , AuthorizationGrant grant ,
44
47
Client client , AppConfiguration appConfiguration , AttributeService attributeService ) {
@@ -50,8 +53,13 @@ public ExternalUpdateTokenContext(HttpServletRequest httpRequest, AuthorizationG
50
53
}
51
54
52
55
public static ExternalUpdateTokenContext of (ExecutionContext executionContext ) {
56
+ return of (executionContext , null );
57
+ }
58
+
59
+ public static ExternalUpdateTokenContext of (ExecutionContext executionContext , JwtSigner jwtSigner ) {
53
60
ExternalUpdateTokenContext context = new ExternalUpdateTokenContext (executionContext .getHttpRequest (), executionContext .getGrant (), executionContext .getClient (), executionContext .getAppConfiguration (), executionContext .getAttributeService ());
54
61
context .setExecutionContext (executionContext );
62
+ context .setJwtSigner (jwtSigner );
55
63
return context ;
56
64
}
57
65
@@ -72,6 +80,23 @@ private ExecutionContext createExecutionContext() {
72
80
return result ;
73
81
}
74
82
83
+ public JwtClaims getClaims () {
84
+ Jwt jwt = getJwt ();
85
+ return jwt != null ? jwt .getClaims () : null ;
86
+ }
87
+
88
+ public Jwt getJwt () {
89
+ return jwtSigner != null ? jwtSigner .getJwt () : null ;
90
+ }
91
+
92
+ public JwtSigner getJwtSigner () {
93
+ return jwtSigner ;
94
+ }
95
+
96
+ public void setJwtSigner (JwtSigner jwtSigner ) {
97
+ this .jwtSigner = jwtSigner ;
98
+ }
99
+
75
100
public CustomScriptConfiguration getScript () {
76
101
return script ;
77
102
}
@@ -117,13 +142,9 @@ public void overwriteAccessTokenScopes(AccessToken accessToken, Set<String> newS
117
142
118
143
grant .setScopes (newScopes );
119
144
120
- // re-generate access token jwt to put new scopes into jwt
121
- if (isValidJwt (accessToken .getCode ())) {
122
- try {
123
- accessToken .setCode (grant .createAccessTokenAsJwt (accessToken , executionContext ));
124
- } catch (Exception e ) {
125
- log .error ("Failed to generate access token jwt" , e );
126
- }
145
+ final Jwt jwt = getJwt ();
146
+ if (jwt != null ) {
147
+ jwt .getClaims ().setClaim ("scope" , Lists .newArrayList (newScopes ));
127
148
}
128
149
}
129
150
0 commit comments