Skip to content

Commit

Permalink
Update Sources/ImperialShopify/ShopifyRouter.swift
Browse files Browse the repository at this point in the history
Co-authored-by: Vamsi Madduluri <[email protected]>
  • Loading branch information
fpseverino and vamsii777 authored Nov 22, 2024
1 parent cb9f630 commit 0ab3d8a
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions Sources/ImperialShopify/ShopifyRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0ab3d8a

Please sign in to comment.