@@ -29,6 +29,11 @@ type RefreshTokenGrantHandler struct {
29
29
fosite.AudienceStrategyProvider
30
30
fosite.RefreshTokenScopesProvider
31
31
}
32
+
33
+ // IgnoreRequestedScopeNotInOriginalGrant determines the action to take when the requested scopes in the refresh
34
+ // flow were not originally granted. If false which is the default the handler will automatically return an error.
35
+ // If true the handler will filter out / ignore the scopes which were not originally granted.
36
+ IgnoreRequestedScopeNotInOriginalGrant bool
32
37
}
33
38
34
39
// HandleTokenEndpointRequest implements https://tools.ietf.org/html/rfc6749#section-6
@@ -89,12 +94,10 @@ func (c *RefreshTokenGrantHandler) HandleTokenEndpointRequest(ctx context.Contex
89
94
90
95
See https://www.rfc-editor.org/rfc/rfc6749#section-6
91
96
*/
92
- switch scope := request . GetRequestForm (). Get ( "scope" ); scope {
93
- case "" :
94
- // Addresses point 1 of the text in RFC6749 Section 6.
97
+
98
+ // Addresses point 1 of the text in RFC6749 Section 6.
99
+ if len ( request . GetRequestedScopes ()) == 0 {
95
100
request .SetRequestedScopes (originalRequest .GetGrantedScopes ())
96
- default :
97
- request .SetRequestedScopes (fosite .RemoveEmpty (strings .Split (scope , " " )))
98
101
}
99
102
100
103
request .SetRequestedAudience (originalRequest .GetRequestedAudience ())
@@ -103,9 +106,15 @@ func (c *RefreshTokenGrantHandler) HandleTokenEndpointRequest(ctx context.Contex
103
106
originalScopes := originalRequest .GetGrantedScopes ()
104
107
105
108
for _ , scope := range request .GetRequestedScopes () {
106
- // Addresses point 2 of the text in RFC6749 Section 6.
107
109
if ! strategy (originalScopes , scope ) {
108
- return errorsx .WithStack (fosite .ErrInvalidScope .WithHintf ("The requested scope '%s' was not originally granted by the resource owner." , scope ))
110
+ if c .IgnoreRequestedScopeNotInOriginalGrant {
111
+ // Skips addressing point 2 of the text in RFC6749 Section 6 and instead just prevents the scope
112
+ // requested from being granted.
113
+ continue
114
+ } else {
115
+ // Addresses point 2 of the text in RFC6749 Section 6.
116
+ return errorsx .WithStack (fosite .ErrInvalidScope .WithHintf ("The requested scope '%s' was not originally granted by the resource owner." , scope ))
117
+ }
109
118
}
110
119
111
120
if ! strategy (request .GetClient ().GetScopes (), scope ) {
0 commit comments