| 975 | }; |
| 976 | |
| 977 | const normalizedTokenScope = ( |
| 978 | as: oauth.AuthorizationServer, |
| 979 | scope: string | undefined, |
| 980 | ): string | undefined => { |
| 981 | if (scope === undefined || scope.trim().length === 0) return undefined; |
| 982 | const tokenEndpoint = typeof as.token_endpoint === "string" ? URL.parse(as.token_endpoint) : null; |
| 983 | const isSlackTokenEndpoint = |
| 984 | tokenEndpoint?.hostname.toLowerCase() === "slack.com" && |
| 985 | (tokenEndpoint.pathname === "/api/oauth.v2.access" || |
| 986 | tokenEndpoint.pathname === "/api/oauth.v2.user.access"); |
| 987 | if (!isSlackTokenEndpoint) return scope; |
| 988 | |
| 989 | const normalized = scope |
| 990 | .split(/[\s,]+/) |
| 991 | .filter(Boolean) |
| 992 | .join(" "); |
| 993 | return normalized.length > 0 ? normalized : undefined; |
| 994 | }; |
| 995 | |
| 996 | const tokenResponseFrom = ( |
| 997 | as: oauth.AuthorizationServer, |