¶ Github login
Update Time: 2025-02-18 09:00:47
¶ Preparation
Configure in Github Developer Settings (opens new window) and Authing Console (opens new window).
¶ Integrate Github login
¶ Step 1: Add Github dependency
Enter: https://github.com/Authing/authing-binary in the swift package search bar.
Authing-binary (opens new window) depends on Guard-iOS SDK (opens new window).
Select Up to Next Major Version 1.0.0 for the dependency rule.
Check Github after Add Package.
Github depends on Guard-iOS 1.4.3 (opens new window) later versions.
¶ Step 2: Initialize Github login
import Guard
import Github
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Authing.start(<#AUTHING_APP_ID#>)
// appId: Github ClientID
// redirectURI: Github authorization callback page
// scope: empty by default
Github.register(appId: <#your_github_appid#>, redirectURI: <#your_github_redirecturi#>, <#your_github_scope#>)
}
¶ Step 3: Initiate Github login authorization
¶ Github authorization login
func login(viewController: UIViewController, completion: @escaping Authing.AuthCompletion) -> Void
parameter
- viewController UIViewController hosting the view
example
Github.login(viewController: <#ViewController#>) { code, message, userInfo in
if (code == 200) {
// login successful
// userInfo
}
}
If the developer integrates Github login by himself, after getting the AuthorizationCode, he can call the following API in exchange for Authing user information:
¶ Login via Github authorization code
func loginByGithub(_ code: String, completion: @escaping(Int, String?, UserInfo?) -> Void)
parameter
code
Github authorization code
example
AuthClient().loginByGithub(authCode) { code, message, userInfo in
if (code == 200) {
// userInfo: user information
}
}