| 749 | }; |
| 750 | |
| 751 | const normalizedTokenScope = ( |
| 752 | as: oauth.AuthorizationServer, |
| 753 | scope: string | undefined, |
| 754 | ): string | undefined => { |
| 755 | if (scope === undefined || scope.trim().length === 0) return undefined; |
| 756 | const tokenEndpoint = typeof as.token_endpoint === "string" ? URL.parse(as.token_endpoint) : null; |
| 757 | const isSlackTokenEndpoint = |
| 758 | tokenEndpoint?.hostname.toLowerCase() === "slack.com" && |
| 759 | (tokenEndpoint.pathname === "/api/oauth.v2.access" || |
| 760 | tokenEndpoint.pathname === "/api/oauth.v2.user.access"); |
| 761 | if (!isSlackTokenEndpoint) return scope; |
| 762 | |
| 763 | const normalized = scope |
| 764 | .split(/[\s,]+/) |
| 765 | .filter(Boolean) |
| 766 | .join(" "); |
| 767 | return normalized.length > 0 ? normalized : undefined; |
| 768 | }; |
| 769 | |
| 770 | const tokenResponseFrom = ( |
| 771 | as: oauth.AuthorizationServer, |