-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathAuthAPICustomTokenExchangeMethodHandler.swift
More file actions
48 lines (42 loc) · 1.73 KB
/
Copy pathAuthAPICustomTokenExchangeMethodHandler.swift
File metadata and controls
48 lines (42 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import Auth0
#if os(iOS)
import Flutter
#else
import FlutterMacOS
#endif
struct AuthAPICustomTokenExchangeMethodHandler: MethodHandler {
enum Argument: String {
case subjectToken
case subjectTokenType
case audience
case scopes
case organization
}
let client: Authentication
func handle(with arguments: [String: Any], callback: @escaping FlutterResult) {
guard let subjectToken = arguments[Argument.subjectToken] as? String else {
return callback(FlutterError(from: .requiredArgumentMissing(Argument.subjectToken.rawValue)))
}
guard let subjectTokenType = arguments[Argument.subjectTokenType] as? String else {
return callback(FlutterError(from: .requiredArgumentMissing(Argument.subjectTokenType.rawValue)))
}
guard let scopes = arguments[Argument.scopes] as? [String], !scopes.isEmpty else {
return callback(FlutterError(from: .requiredArgumentMissing(Argument.scopes.rawValue)))
}
let scope = scopes.asSpaceSeparatedString
let audience = arguments[Argument.audience] as? String
let organization = arguments[Argument.organization] as? String
client
.customTokenExchange(subjectToken: subjectToken,
subjectTokenType: subjectTokenType,
audience: audience,
scope: scope,
organization: organization)
.start {
switch $0 {
case .success(let credentials): callback(self.result(from: credentials))
case .failure(let error): callback(FlutterError(from: error))
}
}
}
}