Skip to content

Commit

Permalink
Call a ClearRefreshToken before selecting a new GoogleSheet to be sure
Browse files Browse the repository at this point in the history
to cancel the identity (RefreshToken) of the currently logged in user.
This way the user can select a different identity each time he selects a
Google Sheet.
  • Loading branch information
opicciotto committed Aug 26, 2024
1 parent 1cb7eb0 commit f158d5b
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 123 deletions.
1 change: 1 addition & 0 deletions _c8oProject/mobileApplication.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ componentScriptContent:
tplProjectName: mobilebuilder_tpl_8_3_0_ngx
↓DisplayGoogleDrivePicker [ngx.components.UIActionStack-1723642068753]: 🗏 mobileSharedActions/DisplayGoogleDrivePicker.yaml
↓Configure [ngx.components.PageComponent-1723642068777]: 🗏 mobilePages/Configure.yaml
↓TestOnly [ngx.components.PageComponent-1724657032162]: 🗏 mobilePages/TestOnly.yaml
↓Style [ngx.components.UIStyle-1723648569770]:
comment: You can add some global application styles here
styleContent:
Expand Down
17 changes: 17 additions & 0 deletions _c8oProject/mobilePages/TestOnly.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
comment: This is a Test page to launch before calling BackEnd seqeunces. This will login using the DEMO user profile
segment: path-to-testonly
title: Title for TestOnly
↓PageEvent [ngx.components.UIPageEvent-1724657111553]:
↓CallSequence [ngx.components.UIDynamicAction-1724657119153]:
beanData: '{"ionBean":"CallSequenceAction","requestable":"plain:lib_GoogleSheet.TestLogin"}'
↓H1 [ngx.components.UIDynamicElement-1724657194249]:
beanData: '{"ionBean":"Heading1"}'
tagName: h1
↓Text [ngx.components.UIText-1724657194248]:
textValue:
- xmlizable:
- ↑classname: com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType
- MobileSmartSourceType: plain:You are now logged in as DEMO
↓Content [ngx.components.UIDynamicElement-1724657178635]:
beanData: '{"ionBean":"Content"}'
tagName: ion-content
232 changes: 112 additions & 120 deletions _c8oProject/mobileSharedActions/DisplayGoogleDrivePicker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,125 +12,117 @@ comment: |
'
↓CallSequence [ngx.components.UIDynamicAction-1723642068756]:
beanData: '{"ionBean":"CallSequenceAction","requestable":"plain:lib_OAuth.GetOAuthCredentials"}'
↓OAuthLogin [ngx.components.UIDynamicAction-1723642068759]:
beanData: |
'{
"ionBean": "OAuthLoginAction",
"provider": "plain:openid",
"clientid": "source:{\"filter\":\"Sequence\",\"project\":\"GoogleSpeadSheetDemo\",\"input\":\"\",\"model\":{\"data\":[{\"sequence\":\"lib_OAuth.GetOAuthCredentials\",\"marker\":\"\"}],\"path\":\"?.GoogleClientID\",\"prefix\":\"\",\"suffix\":\"\",\"custom\":\"\",\"useCustom\":false}}",
"scope": "plain:https:\/\/www.googleapis.com\/auth\/userinfo.email https:\/\/www.googleapis.com\/auth\/userinfo.profile https:\/\/www.googleapis.com\/auth\/spreadsheets https:\/\/www.googleapis.com\/auth\/drive.file&access_type=offline&prompt=consent",
"response_type": "plain:code",
"loginRequestable": "plain:lib_GoogleSheet.loginGoogleWithCode",
"checkAccessTokenRequestable": "plain:lib_GoogleSheet.checkAccessTokenGoogle",
"authorization_endpoint": "plain:https:\/\/accounts.google.com\/o\/oauth2\/v2\/auth",
"callbackurl": "plain:https:\/\/c8ocloud.convertigo.net\/convertigo\/projects\/lib_OAuth\/getTokenGoogle.html"
}'
↓If [ngx.components.UIDynamicAction-1723980941990]:
beanData: '{"ionBean":"IfAction","condition":"script:parent.out.refreshToken"}'
isEnabled: false
↓SetGlobal [ngx.components.UIDynamicAction-1723979461352]:
beanData: |
'{
"ionBean": "SetGlobalAction",
"Property": "plain:refreshToken",
"Value": "source:{\"filter\":\"Action\",\"project\":\"lib_GoogleSheet\",\"input\":\"\",\"model\":{\"data\":[{\"priority\":1723642068759,\"rootEvent\":false,\"pageLocals\":false},{\"priority\":1723642068753,\"rootEvent\":false,\"pageLocals\":false},{\"priority\":1723642068756,\"rootEvent\":false,\"pageLocals\":false}],\"path\":\"?.out\",\"prefix\":\"\",\"suffix\":\"?.refreshToken\",\"custom\":\"\",\"useCustom\":false}}"
}'
↓CallSequence1 [ngx.components.UIDynamicAction-1723642068762]:
beanData: '{"ionBean":"CallSequenceAction","requestable":"plain:lib_GoogleSheet.checkAccessTokenGoogle"}'
↓CallSequence [ngx.components.UIDynamicAction-1723642068765]:
beanData: '{"ionBean":"CallSequenceAction","requestable":"plain:lib_GoogleSheet.getApiKey"}'
↓DisplayPicker [ngx.components.UICustomAction-1723642068768]:
actionValue:
- xmlizable:
- ↑classname: com.twinsoft.convertigo.beans.common.FormatedContent
- com.twinsoft.convertigo.beans.common.FormatedContent:
: |
' // The Browser API key obtained from the Google API Console.
// Replace with your own Browser API key, or your own key.
var developerKey = vars.apiKey;
// Replace with your own project number from console.developers.google.com.
// See "Project number" under "IAM & Admin" > "Settings"
var appId = "439803111105";
var pickerApiLoaded = false;
// Use the Google API Loader script to load the google.picker script.
var onPickerApiLoad = function () {
pickerApiLoaded = true;
createPicker();
}
// Create and render a Picker object for searching images.
var createPicker = function () {
if (pickerApiLoaded && vars.oauthToken) {
var view = new window["google"].picker.View(window["google"].picker.ViewId.DOCS);
view.setMimeTypes("application/vnd.google-apps.spreadsheet");
var picker = new window["google"].picker.PickerBuilder()
.enableFeature(window["google"].picker.Feature.NAV_HIDDEN)
.enableFeature(window["google"].picker.Feature.MULTISELECT_ENABLED)
.setAppId(appId)
.setOAuthToken(vars.oauthToken)
.addView(view)
.addView(new window["google"].picker.DocsUploadView())
.setDeveloperKey(developerKey)
.setCallback(pickerCallback)
.build();
picker.setVisible(true);
}
}
// A simple callback implementation.
var pickerCallback = function (data) {
if (data.action == window["google"].picker.Action.PICKED) {
var fileId = data.docs[0].id;
resolve(fileId);
}
}
// Load the Google Apis and when load finished, start installation process..
load(''https://apis.google.com/js/api.js'', function (err, script) {
if (err) {
page.c8o.log.error(''[Google APis] ''+ err);
}
else {
window["gapi"].load(''picker'', {
''callback'': onPickerApiLoad
});
}
});
'
package_dependencies:
- xmlizable:
- ↑classname: com.twinsoft.convertigo.beans.common.XMLVector
- com.twinsoft.convertigo.beans.common.XMLVector:
- xmlizable:
- ↑classname: com.twinsoft.convertigo.beans.common.XMLVector
- com.twinsoft.convertigo.beans.common.XMLVector:
- java.lang.String:
- ↑value: load-script
- java.lang.String:
- ↑value: 1.0.0
page_ts_imports:
- xmlizable:
- ↑classname: com.twinsoft.convertigo.beans.common.XMLVector
- com.twinsoft.convertigo.beans.common.XMLVector:
- xmlizable:
- ↑classname: com.twinsoft.convertigo.beans.common.XMLVector
- com.twinsoft.convertigo.beans.common.XMLVector:
- java.lang.String:
- ↑value: '* as load'
- java.lang.String:
- ↑value: load-script
↓oauthToken [ngx.components.UIControlVariable-1723642068771]:
comment: the Google OAuth token coming from an OAuth/OpenID login action
varValue:
↓CallSequence [ngx.components.UIDynamicAction-1724656552975]:
beanData: '{"ionBean":"CallSequenceAction","requestable":"plain:lib_GoogleSheet.ClearRefreshToken"}'
↓OAuthLogin [ngx.components.UIDynamicAction-1723642068759]:
beanData: |
'{
"ionBean": "OAuthLoginAction",
"provider": "plain:openid",
"clientid": "source:{\"filter\":\"Sequence\",\"project\":\"GoogleSpeadSheetDemo\",\"input\":\"\",\"model\":{\"data\":[{\"sequence\":\"lib_OAuth.GetOAuthCredentials\",\"marker\":\"\"}],\"path\":\"?.GoogleClientID\",\"prefix\":\"\",\"suffix\":\"\",\"custom\":\"\",\"useCustom\":false}}",
"scope": "plain:https:\/\/www.googleapis.com\/auth\/userinfo.email https:\/\/www.googleapis.com\/auth\/userinfo.profile https:\/\/www.googleapis.com\/auth\/spreadsheets https:\/\/www.googleapis.com\/auth\/drive.file&access_type=offline&prompt=consent",
"response_type": "plain:code",
"loginRequestable": "plain:lib_GoogleSheet.loginGoogleWithCode",
"checkAccessTokenRequestable": "plain:lib_GoogleSheet.checkAccessTokenGoogle",
"authorization_endpoint": "plain:https:\/\/accounts.google.com\/o\/oauth2\/v2\/auth",
"callbackurl": "plain:https:\/\/c8ocloud.convertigo.net\/convertigo\/projects\/lib_OAuth\/getTokenGoogle.html"
}'
↓CallSequence1 [ngx.components.UIDynamicAction-1723642068762]:
beanData: '{"ionBean":"CallSequenceAction","requestable":"plain:lib_GoogleSheet.checkAccessTokenGoogle"}'
↓CallSequence [ngx.components.UIDynamicAction-1723642068765]:
beanData: '{"ionBean":"CallSequenceAction","requestable":"plain:lib_GoogleSheet.getApiKey"}'
↓DisplayPicker [ngx.components.UICustomAction-1723642068768]:
actionValue:
- xmlizable:
- ↑classname: com.twinsoft.convertigo.beans.common.FormatedContent
- com.twinsoft.convertigo.beans.common.FormatedContent:
: |
' // The Browser API key obtained from the Google API Console.
// Replace with your own Browser API key, or your own key.
var developerKey = vars.apiKey;
// Replace with your own project number from console.developers.google.com.
// See "Project number" under "IAM & Admin" > "Settings"
var appId = "439803111105";
var pickerApiLoaded = false;
// Use the Google API Loader script to load the google.picker script.
var onPickerApiLoad = function () {
pickerApiLoaded = true;
createPicker();
}
// Create and render a Picker object for searching images.
var createPicker = function () {
if (pickerApiLoaded && vars.oauthToken) {
var view = new window["google"].picker.View(window["google"].picker.ViewId.DOCS);
view.setMimeTypes("application/vnd.google-apps.spreadsheet");
var picker = new window["google"].picker.PickerBuilder()
.enableFeature(window["google"].picker.Feature.NAV_HIDDEN)
.enableFeature(window["google"].picker.Feature.MULTISELECT_ENABLED)
.setAppId(appId)
.setOAuthToken(vars.oauthToken)
.addView(view)
.addView(new window["google"].picker.DocsUploadView())
.setDeveloperKey(developerKey)
.setCallback(pickerCallback)
.build();
picker.setVisible(true);
}
}
// A simple callback implementation.
var pickerCallback = function (data) {
if (data.action == window["google"].picker.Action.PICKED) {
var fileId = data.docs[0].id;
resolve(fileId);
}
}
// Load the Google Apis and when load finished, start installation process..
load(''https://apis.google.com/js/api.js'', function (err, script) {
if (err) {
page.c8o.log.error(''[Google APis] ''+ err);
}
else {
window["gapi"].load(''picker'', {
''callback'': onPickerApiLoad
});
}
});
'
package_dependencies:
- xmlizable:
- ↑classname: com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType
- MobileSmartSourceType: source:{"filter":"Action","project":"lib_GoogleSheet","input":"","model":{"data":[{"priority":1723642068762,"rootEvent":false,"pageLocals":false},{"priority":1723642068753,"rootEvent":false,"pageLocals":false},{"priority":1723642068756,"rootEvent":false,"pageLocals":false},{"priority":1723642068759,"rootEvent":false,"pageLocals":false}],"path":"?.out?.token","prefix":"","suffix":"","custom":"","useCustom":false}}
↓apiKey [ngx.components.UIControlVariable-1723642068774]:
comment: The Display Picker API Key
varValue:
- ↑classname: com.twinsoft.convertigo.beans.common.XMLVector
- com.twinsoft.convertigo.beans.common.XMLVector:
- xmlizable:
- ↑classname: com.twinsoft.convertigo.beans.common.XMLVector
- com.twinsoft.convertigo.beans.common.XMLVector:
- java.lang.String:
- ↑value: load-script
- java.lang.String:
- ↑value: 1.0.0
page_ts_imports:
- xmlizable:
- ↑classname: com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType
- MobileSmartSourceType: source:{"filter":"Action","project":"lib_GoogleSheet","input":"","model":{"data":[{"priority":1723642068765,"rootEvent":false,"pageLocals":false},{"priority":1723642068753,"rootEvent":false,"pageLocals":false},{"priority":1723642068756,"rootEvent":false,"pageLocals":false},{"priority":1723642068759,"rootEvent":false,"pageLocals":false},{"priority":1723642068762,"rootEvent":false,"pageLocals":false}],"path":"?.out?.apiKey","prefix":"","suffix":"","custom":"","useCustom":false}}
- ↑classname: com.twinsoft.convertigo.beans.common.XMLVector
- com.twinsoft.convertigo.beans.common.XMLVector:
- xmlizable:
- ↑classname: com.twinsoft.convertigo.beans.common.XMLVector
- com.twinsoft.convertigo.beans.common.XMLVector:
- java.lang.String:
- ↑value: '* as load'
- java.lang.String:
- ↑value: load-script
↓oauthToken [ngx.components.UIControlVariable-1723642068771]:
comment: the Google OAuth token coming from an OAuth/OpenID login action
varValue:
- xmlizable:
- ↑classname: com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType
- MobileSmartSourceType: source:{"filter":"Action","project":"lib_GoogleSheet","input":"","model":{"data":[{"priority":1723642068762,"rootEvent":false,"pageLocals":false},{"priority":1723642068753,"rootEvent":false,"pageLocals":false},{"priority":1723642068756,"rootEvent":false,"pageLocals":false},{"priority":1723642068759,"rootEvent":false,"pageLocals":false}],"path":"?.out?.token","prefix":"","suffix":"","custom":"","useCustom":false}}
↓apiKey [ngx.components.UIControlVariable-1723642068774]:
comment: The Display Picker API Key
varValue:
- xmlizable:
- ↑classname: com.twinsoft.convertigo.beans.ngx.components.MobileSmartSourceType
- MobileSmartSourceType: source:{"filter":"Action","project":"lib_GoogleSheet","input":"","model":{"data":[{"priority":1723642068765,"rootEvent":false,"pageLocals":false},{"priority":1723642068753,"rootEvent":false,"pageLocals":false},{"priority":1723642068756,"rootEvent":false,"pageLocals":false},{"priority":1723642068759,"rootEvent":false,"pageLocals":false},{"priority":1723642068762,"rootEvent":false,"pageLocals":false}],"path":"?.out?.apiKey","prefix":"","suffix":"","custom":"","useCustom":false}}
23 changes: 23 additions & 0 deletions _c8oProject/sequences/ClearRefreshToken.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
accessibility: Hidden
authenticatedUserAsCacheKey: true
comment: Remove any RefreshToken and GoogleSheetAcessTokne form the session and user profile
↓Remove_from_session [steps.SessionRemoveStep-1724598809201]:
key: oAuthAccessTokenGoogleSheet
↓authenticatedUserID [steps.GetAuthenticatedUserStep-1724598856296]:
↓Call_Sequence [steps.SequenceStep-1724598867633]:
sourceSequence: lib_UserManager.SetUserAttribute
↓user [variables.StepVariable-1724598889023]:
comment: The user where we have to set the attribute on
sourceDefinition:
- xmlizable:
- ↑classname: com.twinsoft.convertigo.beans.common.XMLVector
- com.twinsoft.convertigo.beans.common.XMLVector:
- java.lang.String:
- ↑value: 1724598856296
- java.lang.String:
- ↑value: ./text()
↓attribute [variables.StepVariable-1724598889025]:
comment: The attribute name
value: GoogleOAuthRefreshToken
↓value [variables.StepVariable-1724598889027]:
comment: The attribute value
Loading

0 comments on commit f158d5b

Please sign in to comment.