Skip to content

Conversation

@Semerokozlyat
Copy link

Check Introspectable Resource Namespaces in JWT header to decide if hybrid token must be introspected

Closes PLTFRM-84867

@Semerokozlyat Semerokozlyat force-pushed the feature/PLTFRM-84867-introspect-token-on-condition-hybrid-rns branch from f350ce4 to c681f21 Compare December 31, 2025 12:37
return false
}
for i := range scopeFilter {
sfRN := strings.ToLower(strings.TrimSpace(scopeFilter[i].ResourceNamespace))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use strings.EqualFold (https://pkg.go.dev/strings#EqualFold) instead of strings.ToLower() to avoid memory allocation for case when resource namespace or irn's item contains upper case letter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

continue
}
for _, iRN := range introspectableRNsArr {
if sfRN == strings.ToLower(strings.TrimSpace(iRN.(string))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If irn contains non-string array, panic will be. Suggest asserting to []string above.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately it is not possible since json decoder returns []interface{} even if it was initially slice of strings.
I added "ok" notation to the type assertion of the individual slice element to avoid panic here

}
for i := range scopeFilter {
sfRN := strings.ToLower(strings.TrimSpace(scopeFilter[i].ResourceNamespace))
if sfRN == "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to handle empty resource namespace separately? As I know, we may have empty rs in the scope filter.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed, added empty string as a valid case.


const JWTTypeAppAccessToken = "application/at+jwt"

const JWTHeaderFieldIRN = "irn" // array of Resource Namespaces for roles available after token introspection only
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment what irn means hear - introspectable resource namespace.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

// 1. nri field indicates introspection is required (nri absent/false/0)
// 2. irn (Introspectable Resource Namespace) field contains list of Resource Namespaces matching the scopeFilter
func checkIntrospectionRequiredByJWTHeader(jwtHeader map[string]interface{}, scopeFilter jwt.ScopeFilter) bool {
return introspectionRequiredByNRIField(jwtHeader) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest checking "nri" only if "irn" is missing since the first is deprecated (pls add a comment about it). Otherwise, will be not be able to remove "nri" in the future - this library will not be ready for it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed.

@Semerokozlyat Semerokozlyat force-pushed the feature/PLTFRM-84867-introspect-token-on-condition-hybrid-rns branch 3 times, most recently from 8032e78 to 1cbdc3e Compare January 6, 2026 15:49
…ybrid token must be introspected, closes PLTFRM-84867
@Semerokozlyat Semerokozlyat force-pushed the feature/PLTFRM-84867-introspect-token-on-condition-hybrid-rns branch from 1cbdc3e to 43fe8ff Compare January 6, 2026 15:54
continue
}
if strings.EqualFold(
strings.TrimSpace(scopeFilter[i].ResourceNamespace),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move space trimming outside of the nested cycle

}

func introspectionRequiredByNRIField(jwtHeader map[string]interface{}) bool {
notRequiredIntrospection, ok := jwtHeader["nri"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since you defined a const JWTHeaderFieldIRN, may I ask you to define another const for the "nri" header as well with small comment what is it and highlight that that header will be deprecated soon?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants