Credit of this blog goes to withsp
Hello today we’ll talk about integration between K2 and Google GSuite. Pre-requisite as below
- K2 Five version 5.0001.1000.1 or above (version date is 28 Nov 2017)
- Google account
Firstly, we need to prepare google service that we want to intergrate with. Url for enable service is https://console.developers.google.com/apis. You need to signin with google account. Click Library tab on the left.
In our example we’ll use Google Drive API.
Click Enable button
Then go to tab Credentials and select OAuth consent screen. Select your email and enter Product Name
After Save click at Credentials again and select Create credentials => OAuth client ID
After created, we’ll get Client ID and Client secret. These will use to register with K2. So we’ll finish setup Google side.
Open your K2 management site and navigate to Authentication => OAuth => Resource Types. Create your new OAuth Resource Type
Next step is create Resource Type Parameters at the bottom view
After finish, navigate to OAuth => Resources. Create your new OAuth Resource and select Resource Type as your created resource from previous step. Input Authorization Endpoint as https://accounts.google.com/o/oauth2/auth and Token Endpoint as https://accounts.google.com/o/oauth2/token
Next step is configure parameter for OAuth Resource
- client_id and client_secret input information that we got from Google.
- response_type input Authorization Value as code
- scope input as https://www.googleapis.com/auth/drive
- redirect_uri input Authorization Value and Token Value as K2 site url append with /identity/token/oauth/2
- grant_type input Token Value as authorization_code
- access_type input Authorization Value and Token Value as online
After finish we’ll have OAuth resource ready to use in service instance configuration. For configure REST service instance we need to have json of service that we want to use. For Google Drive we can search at https://apis.guru/browse-apis/
Next step we’ll register REST service. Select Authentication Type as OAuth and select our OAuth Resource from previous step
If we found above error, don’t be panic. After you finish OK, system will open browser for you to authentication with google. After you input username password and follow instruction on screen. You will navigate to Authorization Successful screen.
Try adding service instance again. You should be able to create new service instance. Then you can create SmartObject to get data from Google Drive as expected.
Step for create OAuth in K2 reference from https://help.k2.com/kb001702. Google API document can found in google website that you for enable services. If you have question, please feel free to ask. See you next time 🙂