From 0ab3d8a0f61ada39e159723524cfd9153d33be8c Mon Sep 17 00:00:00 2001 From: Francesco Paolo Severino <96546612+fpseverino@users.noreply.github.com> Date: Fri, 22 Nov 2024 22:35:03 +0100 Subject: [PATCH] Update Sources/ImperialShopify/ShopifyRouter.swift Co-authored-by: Vamsi Madduluri --- Sources/ImperialShopify/ShopifyRouter.swift | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Sources/ImperialShopify/ShopifyRouter.swift b/Sources/ImperialShopify/ShopifyRouter.swift index ba4f75f..74ca120 100644 --- a/Sources/ImperialShopify/ShopifyRouter.swift +++ b/Sources/ImperialShopify/ShopifyRouter.swift @@ -26,11 +26,22 @@ final public class ShopifyRouter: FederatedServiceRouter { let nonce = String(UUID().uuidString.prefix(6)) try request.session.setNonce(nonce) - return "https://\(shop)/admin/oauth/authorize?" - + "client_id=\(tokens.clientID)&" - + "scope=\(scope.joined(separator: ","))&" - + "redirect_uri=\(callbackURL)&" - + "state=\(nonce)" + var components = URLComponents() + components.scheme = "https" + components.host = shop + components.path = "/admin/oauth/authorize" + components.queryItems = [ + clientIDItem, + .init(name: "scope", value: scope.joined(separator: ",")), + redirectURIItem, + .init(name: "state", value: nonce), + ] + + guard let url = components.url else { + throw Abort(.internalServerError) + } + + return url.absoluteString } public func callbackBody(with code: String) -> any AsyncResponseEncodable {