You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add support for external signing strategies to the SDK (#43)
* Initial draft of external signature generation
* Updated README.md for signature generation
* Added test for signature generation
* Podspec and changelog
Copy file name to clipboardExpand all lines: CHANGELOG.md
+5-1Lines changed: 5 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,10 @@
1
1
# TransloaditKit Changelog
2
2
3
-
## 3.4
3
+
## 3.5.0
4
+
5
+
* Allow clients to inject only an api key and provide a signature generator closure to calculate signatures for signing requests instead of injecting a key and secret. ([#42](https://github.com/transloadit/TransloaditKit/issues/42))
6
+
7
+
## 3.4.0
4
8
5
9
* Updated Package to depend on exact TUSKit version and removed call to removed method in TUSKit ([#41](https://github.com/transloadit/TransloaditKit/issues/41))
Copy file name to clipboardExpand all lines: README.md
+42Lines changed: 42 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,11 +22,53 @@ dependencies: [
22
22
23
23
Start by initializing `Transloadit`.
24
24
25
+
### Simple initialization; pass key and secret to the SDK
26
+
25
27
```swift
26
28
let credentials = Transloadit.Credentials(key: "SomeKey", secret: "SomeSecret")
27
29
let transloadit =Transloadit(credentials: credentials, session: URLSession.shared)
28
30
```
29
31
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
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
+
30
72
### Create an Assembly
31
73
32
74
To create an `Assembly` you invoke `createAssembly(steps:andUpload:completion)` on `Transloadit`.
@@ -97,7 +114,47 @@ public final class Transloadit {
97
114
/// If left empty, no directory will be made when performing non-file related tasks, such as creating assemblies. However, if you start uploading files,
98
115
/// then TUS will make a directory, whether one you specify or a default one in the documents directory.
/// Initialize Transloadit without a secret, providing a signature generator.
134
+
/// - Parameters:
135
+
/// - apiKey: Transloadit API key.
136
+
/// - sessionConfiguration: A URLSessionConfiguration to use.
137
+
/// - storageDir: A storagedirectory to use. Used by underlying TUSKit mechanism to store files.
138
+
/// If left empty, no directory will be made when performing non-file related tasks, such as creating assemblies. However, if you start uploading files,
139
+
/// then TUS will make a directory, whether one you specify or a default one in the documents directory.
140
+
/// - signatureGenerator: A closure that's invoked to generate the signature for the API request. Implement your own logic to generate a valid
141
+
/// signature. Call the provided completion handler with your signed string or an error as needed.
142
+
///
143
+
/// For example, you can make a request to your backend to generate the signature for you. The closure is passed a string that holds all request params
144
+
/// that need to be signed. See https://transloadit.com/docs/api/authentication/ for more information on signature authentication.
145
+
/// The closure is invoked by the TransloaditAPI when needed.
146
+
///
147
+
/// ** Important:** It's up to the caller to ensure that all codepaths (eventually) call the completion handler. The SDK does not implement any timeouts or fallbacks.
0 commit comments