Get Started
Before you can integrate our service, at least you have an account in Kunber.
Login
- Click "Login/Register" button on top of this page.
- Follow the step until you manage to see the dashboard.
Create App
- Go to "App" menu.
- Click "Create New" button, and fill the form.
- Fill the callback URL with your origin. Let's say
http://localhost:3000
. - Once you hit "Save" button, your app will be listed on the page.
- Click the App name and you will see the App ID and App Secret. We'll use them in the next section.
Integration
Update your database
Add a column to your users table in your database called kunber_id
, string (36 chars).
Create authorization page/endpoint
- Create an HTML page or just a GET endpoint (Callback URL). Let's say
http://localhost:3000/authorize_kunber
. - If any request come to the page/endpoint, you will need to capture the
auth_code
from query string. - Send http POST request to our system (Exchange API). See CURL below.
- Get the user information from the response (UserData). Then you can use it to authenticate the user.
CURL -L -X POST 'https://kunber.zone.id/api/client/{your-app-id}/exchange' \
-H 'Authorization: your-app-secret' \
-H 'Content-Type: application/json' \
--data-raw '{"code": "the_auth_code_goes_here"}'
Create Login button
Create a button/link that will redirect the user to the Onboarding link below.
https://kunber.zone.id/onboarding/{your-app-id}?callback_url=http://localhost:3000/authorize_kunber
Authenticate User
After you get the UserData, now you need to authenticate your user.
Find or create User
- Get the id from UserData (e.g. user-1234) then query to your DB. Find the user where
kunber_id
= "user-1234". - If it doesn't exist, then create a user with
kunber_id
= "user-1234". You may also save all of information from UserData to your users table. - Now, you have the user (e.g. John).
Login mechanism
After you have the User (existing/new), you can log the user in based on your app mecahnism.
- If your app is using JWT, then generate the JWT for John.
- If you use a stateful web framework (e.g. Laravel, AdonisJS, etc), you can just login with the id of John.
- If your app is using cookie, then just generate the cookie for John.
Examples
There two repositories you can check to see how the Kunber implementation works