| 942 | }; |
| 943 | |
| 944 | const normalizedTokenScope = ( |
| 945 | as: oauth.AuthorizationServer, |
| 946 | scope: string | undefined, |
| 947 | ): string | undefined => { |
| 948 | if (scope === undefined || scope.trim().length === 0) return undefined; |
| 949 | const tokenEndpoint = typeof as.token_endpoint === "string" ? URL.parse(as.token_endpoint) : null; |
| 950 | const isSlackTokenEndpoint = |
| 951 | tokenEndpoint?.hostname.toLowerCase() === "slack.com" && |
| 952 | (tokenEndpoint.pathname === "/api/oauth.v2.access" || |
| 953 | tokenEndpoint.pathname === "/api/oauth.v2.user.access"); |
| 954 | if (!isSlackTokenEndpoint) return scope; |
| 955 | |
| 956 | const normalized = scope |
| 957 | .split(/[\s,]+/) |
| 958 | .filter(Boolean) |
| 959 | .join(" "); |
| 960 | return normalized.length > 0 ? normalized : undefined; |
| 961 | }; |
| 962 | |
| 963 | const tokenResponseFrom = ( |
| 964 | as: oauth.AuthorizationServer, |