getProvider
AppDelegate.reachfive().getProvider(name)
Description
Retrieve a provider registered on the ReachFive client by name.
Refer at the iOS SDK Installation to initialize the providers at the client’s instantiation.
|
Usage
For .login, pass the initiating UIViewController wrapped in a Presentation:
try await provider.login(scope: scope, origin: origin, presenting: Presentation(from: self))
Each provider derives what it needs from it, depending on how it authenticates:
-
Web-based providers (
WebProvider, and any provider with no matching native creator, falling back toDefaultProvider) open anASWebAuthenticationSessionand need a presentation context. The SDK derives one from the view controller; if it already implementsASWebAuthenticationPresentationContextProviding, its ownpresentationAnchor(for:)keeps precedence. -
AppleProviderneeds the view controller to be attached to a window at call time. -
Native SDK providers (
GoogleProvider,FacebookProvider,WeChat) need only the view controller itself, or nothing at all.
In every case, call .login from viewDidAppear or a user interaction, not from viewDidLoad, so the view controller is attached to a window.
Examples
import Reach5
let providerName: String = // Here paste the name of the provider
let scope = ["openid", "email", "profile", "phone", "full_write", "offline_access"]
do {
if let provider = AppDelegate.reachfive().getProvider(name: providerName) {
let authToken = try await provider.login(
scope: scope,
origin: "home",
presenting: Presentation(from: self)
)
// Get the profile's authentication token
}
} catch {
// Return a ReachFive error
}
import Reach5
let providerName: String = // Here paste the name of the provider
do {
if let provider = AppDelegate.reachfive().getProvider(name: providerName) {
try await provider.logout()
// Do something
}
} catch {
// Return a ReachFive error
}
Response
Type: Provider
Provider
The provider which name matches the name passed in argument.
name |
The name of the provider. possible values
|
login |
Expect the following arguments:
It authenticates the profile with the provider otherwise it returns a |
logout |
No argument is expected. Kill the SSO session of the profile otherwise returns a |