iOS SDK
Integrate your iOS application with Authgear iOS SDK
Setup Application in Authgear
Signup for an account in https://portal.authgearapps.com/ and create a project. Or you can use your self-deployed Authgear.
After that, we will need to create an application in Authgear.
Create an application
Go to "Applications".
Click "Add Application" in the top right corner
Input name of your application, this is for reference only
Defining a custom scheme that the users will be redirected back to your app after they have authenticated with Authgear. Add the URI to "Redirect URIs". (e.g. com.myapp://host/path).
Click "Save" and keep the client id. You can also obtain the client id from the list later.
If you want to validate JWT access token in your server, select Issue JWT as access token. If you will forward incoming requests to Authgear Resolver Endpoint for authentication, leave this unchecked. See comparisons in Backend Integration.
Install the SDK
CocoaPods
Swift Package Manager
Register URL Scheme for Redirect URI
In your application's Info.plist
, register your custom URL scheme, (e.g. com.myapp
).
Configuration Authgear SDK
SDK must be properly configured before use.
Trigger authenticate
When the user clicks login/signup on your app, you can use the following code to start authorization.
Your user is now logged in!
Using the Access Token in HTTP Requests
Call refreshAccessTokenIfNeeded
every time before using the access token, the function will check and make the network call only if the access token has expired. Include the access token into the Authorization header of your application request.
Logout
To log out the user from the current app session, you need to invoke thelogout
function.
Next steps
To protect your application server from unauthorized access. You will need to integrate your backend with Authgear.
Last updated
Was this helpful?