-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathAuthAPILoginWithFacebookMethodHandler.swift
More file actions
47 lines (41 loc) · 1.58 KB
/
AuthAPILoginWithFacebookMethodHandler.swift
File metadata and controls
47 lines (41 loc) · 1.58 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
import Auth0
#if os(iOS)
import Flutter
#else
import FlutterMacOS
#endif
struct AuthAPILoginWithFacebookMethodHandler: MethodHandler {
enum Argument: String {
case accessToken
case scopes
case parameters
case audience
case profile
}
let client: Authentication
func handle(with arguments: [String: Any], callback: @escaping FlutterResult) {
guard let accessToken = arguments[Argument.accessToken] as? String else {
return callback(FlutterError(from: .requiredArgumentMissing(Argument.accessToken.rawValue)))
}
guard let scopes = arguments[Argument.scopes] as? [String] else {
return callback(FlutterError(from: .requiredArgumentMissing(Argument.scopes.rawValue)))
}
guard let parameters = arguments[Argument.parameters] as? [String: Any] else {
return callback(FlutterError(from: .requiredArgumentMissing(Argument.parameters.rawValue)))
}
let audience = arguments[Argument.audience] as? String
let profile = arguments[Argument.profile] as? [String: Any] ?? [:]
client
.login(facebookSessionAccessToken: accessToken,
profile: profile,
audience: audience,
scope: scopes.asSpaceSeparatedString)
.parameters(parameters)
.start {
switch $0 {
case let .success(credentials): callback(result(from: credentials))
case let .failure(error): callback(FlutterError(from: error))
}
}
}
}