From 3d88fde68e052b2ac2b2ac248e97fa734ec7a501 Mon Sep 17 00:00:00 2001 From: Taylor Dawson Date: Wed, 13 Nov 2024 13:44:35 -0800 Subject: [PATCH 1/3] Rename the proxy header --- Sources/Middleware/ProxyMiddleware.swift | 8 ++++---- docs/proxy-middleware.md | 14 ++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Sources/Middleware/ProxyMiddleware.swift b/Sources/Middleware/ProxyMiddleware.swift index 8857b138..b19af892 100644 --- a/Sources/Middleware/ProxyMiddleware.swift +++ b/Sources/Middleware/ProxyMiddleware.swift @@ -21,11 +21,11 @@ extension ProxyMiddleware: ClientMiddleware { // Save the current full path of the request (baseUrl + request.path) let originalURL = baseURL.appendingPathComponent(request.path ?? "") - // Set the X-Forwarded-For header with the saved original request URL + // Set the X-Turnkey-Request-Url header with the saved original request URL var request = request - let xForwardedForHeader = HTTPField( - name: HTTPField.Name("X-Forwarded-For")!, value: originalURL.absoluteString) - request.headerFields.append(xForwardedForHeader) + let xTurnkeyRequestUrl = HTTPField( + name: HTTPField.Name("X-Turnkey-Request-Url")!, value: originalURL.absoluteString) + request.headerFields.append(xTurnkeyRequestUrl) // Remove the request path and just forward to the proxyBaseURL request.path = "" diff --git a/docs/proxy-middleware.md b/docs/proxy-middleware.md index afea20a2..82d820b1 100644 --- a/docs/proxy-middleware.md +++ b/docs/proxy-middleware.md @@ -19,11 +19,9 @@ This setup is especially useful for operations like: - Wallet import/export - Sub-organization creation -## Important Notes +#### Request Header -#### X-Forwarded-For Header - -The middleware adds an `X-Forwarded-For` header to each request, which contains the original request URL. This is used to forward the request to Turnkey's backend. +The middleware adds an `X-Turnkey-Request-Url` header to each request, which contains the original request URL. This is used to forward the request to Turnkey's backend. Example implementation of a proxy server: @@ -35,10 +33,10 @@ app.use(express.json()); app.post('/api/turnkey-proxy', async (req, res) => { // The original request URL e.g. https://api.turnkey.com/public/v1/submit/email_auth - const turnkeyApiRequestURL = req.headers['x-forwarded-for']; + const turnkeyApiRequestURL = req.headers['X-Turnkey-Request-Url']; - // Remove the 'x-forwarded-for' header - delete req.headers['x-forwarded-for']; + // Remove the 'X-Turnkey-Request-Url' header + delete req.headers['X-Turnkey-Request-Url']; try { // Forward the request to the original URL @@ -71,4 +69,4 @@ It is crucial that the response from the developer's backend matches exactly wit ## Conclusion -While `ProxyMiddleware` is not required, it provides a convenient way to send requests on behalf of unauthenticated users looking to perform +WhWhile `ProxyMiddleware` is not required, it provides a convenient way to send requests on behalf of unauthenticated users looking to perform operations such as email authentication/recovery, wallet import/export, and sub-organization creation. From ea3fe3bd98082d9cc4c995c126149cb3a4313643 Mon Sep 17 00:00:00 2001 From: Taylor Dawson Date: Wed, 13 Nov 2024 13:45:38 -0800 Subject: [PATCH 2/3] Fix typo --- docs/proxy-middleware.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/proxy-middleware.md b/docs/proxy-middleware.md index 82d820b1..e9a0c1b2 100644 --- a/docs/proxy-middleware.md +++ b/docs/proxy-middleware.md @@ -69,4 +69,4 @@ It is crucial that the response from the developer's backend matches exactly wit ## Conclusion -WhWhile `ProxyMiddleware` is not required, it provides a convenient way to send requests on behalf of unauthenticated users looking to perform operations such as email authentication/recovery, wallet import/export, and sub-organization creation. +While `ProxyMiddleware` is not required, it provides a convenient way to send requests on behalf of unauthenticated users looking to perform operations such as email authentication/recovery, wallet import/export, and sub-organization creation. From e7503e8192cbe2b467e29c29130b0a4fc27083db Mon Sep 17 00:00:00 2001 From: Taylor Dawson Date: Wed, 13 Nov 2024 15:22:19 -0800 Subject: [PATCH 3/3] Update readme for latest version --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2c6274b3..ed2479a6 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ The TurnkeySDK is built to support macOS, iOS, tvOS, watchOS, and visionOS, maki To integrate the TurnkeySDK into your Swift project, you need to add it as a dependency in your Package.swift file: ```swift -.package(url: "https://github.com/tkhq/swift-sdk", from: "1.1.0") +.package(url: "https://github.com/tkhq/swift-sdk", from: "1.2.0") ``` ## Usage