| 926 | }; |
| 927 | |
| 928 | const normalizedTokenScope = ( |
| 929 | as: oauth.AuthorizationServer, |
| 930 | scope: string | undefined, |
| 931 | ): string | undefined => { |
| 932 | if (scope === undefined || scope.trim().length === 0) return undefined; |
| 933 | const tokenEndpoint = typeof as.token_endpoint === "string" ? URL.parse(as.token_endpoint) : null; |
| 934 | const isSlackTokenEndpoint = |
| 935 | tokenEndpoint?.hostname.toLowerCase() === "slack.com" && |
| 936 | (tokenEndpoint.pathname === "/api/oauth.v2.access" || |
| 937 | tokenEndpoint.pathname === "/api/oauth.v2.user.access"); |
| 938 | if (!isSlackTokenEndpoint) return scope; |
| 939 | |
| 940 | const normalized = scope |
| 941 | .split(/[\s,]+/) |
| 942 | .filter(Boolean) |
| 943 | .join(" "); |
| 944 | return normalized.length > 0 ? normalized : undefined; |
| 945 | }; |
| 946 | |
| 947 | const tokenResponseFrom = ( |
| 948 | as: oauth.AuthorizationServer, |