Skip to content

Commit f422fec

Browse files
committed
Updated README.md for signature generation
1 parent ccc45e1 commit f422fec

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,53 @@ dependencies: [
2222

2323
Start by initializing `Transloadit`.
2424

25+
### Simple initialization; pass key and secret to the SDK
26+
2527
```swift
2628
let credentials = Transloadit.Credentials(key: "SomeKey", secret: "SomeSecret")
2729
let transloadit = Transloadit(credentials: credentials, session: URLSession.shared)
2830
```
2931

32+
Certain transloadit endpoints (can) require signatures to be included in their requests. The SDK can automatically generate signatures on your behalf but this requires you to pass both your Transloadit key _and_ secret to the SDK.
33+
34+
The SDK does not persist your secret locally beyond the SDK's lifetime.
35+
36+
This means that you're free to obtain your SDK secret in a secure manner from an external host or that you can include it in your app binary. It's up to you.
37+
38+
It's also possible to initialize the SDK with a `nil` secret and manage signing yourself.
39+
40+
### Advanced initialization; omit secret for manual request signing
41+
42+
If, for security reasons, you choose to not expose your API secret to the app in any way, shape, or form, you can manage signature generation yourself. This allows you to generate signatures on your server and provide them to Transloadit as needed.
43+
44+
To do this, use the `Transloadit` initializer that takes an api key and a `signatureGenerator`
45+
46+
```swift
47+
let transloadit = Transloadit(
48+
apiKey: "YOUR-API-KEY",
49+
sessionConfiguration: .default,
50+
signatureGenerator: { stringToSign, onSignatureGenerated in
51+
mySigningService.sign(stringToSign) { result in
52+
onSignatureGenerated(result)
53+
}
54+
})
55+
```
56+
57+
The signature generator is defined as follows:
58+
59+
```swift
60+
public typealias SignatureCompletion = (Result<String, Error>) -> Void
61+
public typealias SignatureGenerator = (String, SignatureCompletion) -> Void
62+
```
63+
64+
The generator itself is passed a string that needs to be signed (a JSON representation of the request parameters that you're generating a signature for) and a closure that you _must_ call to inform the SDK when you're done generating the signature (whether it's successful or failed).
65+
66+
**Important** if you don't call the completion handler, your requests will never be sent. The SDK does not implement a fallback or timeout.
67+
68+
The SDK will invoke the signature generator for every request that requires a signature. It will pass a parameter string for each request to your closure which you can then send to your service (local or external) for signature generation.
69+
70+
To learn more about signature generation see this page: https://transloadit.com/docs/api/authentication/
71+
3072
### Create an Assembly
3173

3274
To create an `Assembly` you invoke `createAssembly(steps:andUpload:completion)` on `Transloadit`.

0 commit comments

Comments
 (0)