bvstone

GreenTools for Google Apps (G4G) v15.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page

Posted:

GreenTools for Google Apps (G4G) v15.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page

With GreenTools for Google Apps (G4G) v15.00 and up you are now able to complete service registration for accounts using ILE functions instead of the G4GREGSVC command.  This is useful for shops that have custom screens or are web based only, and don't have the option of running commands from a command line.

We have also set up a RESTful API endpoint that allows you to send us your unique state code and a URL that you would like our site to redirect to when registration is complete.  

The new functions are used as follows:

g4g_getRegistrationURL() - Retrieve the Google Registration URL

// get a unique Code and URL 
g4g_setValue('id':'bvstone@gmail.com');                            
g4g_setValue('service':'*DRIVE');
rc = g4g_getRegistrationURL(outStateCode:outURL:errMsg);     

Once this is called, the g4g_getRegistrationURL function will return two very important pieces of information:

  1. The outStateCode - This will be a unique ID that you will need to use to retrieve your token once the user has competed the registration process with Google.  This code will also be used for URL redirection should you require that.
  2. outURL - This is a direct link URL to Google where the user will sign into their Google Account and authorize G4G to the required scopes and permissions.  You can either display this as a link for the user to click, or direct them automatically (in the case that this is a web application). 

    Because of the callbacks required for OAuth 2.0, once the user accepts the permissions from Google they will be redirected back to a web page at BVSTools with instructions on how to complete the process. 

    OPTIONAL: If you would like them to be redirected to a site of your choosing, this can also be accomplished by calling a RESTful API we have set up.  Contact us for the endpoint to use.  The data will be JSON data and formatted as follows:
    {
         "state_code":"C4XPgffaaCNV2BiROAJMG2xx",
         "redirect_url":"https://www.yourpath.com/endpoint?field1=data1&field2=data2..."
    }

    The state_code value will be the code returned in the outStateCode output paramter of the g4g_getRegistrationURL() function.  The redirect_url value will be where you would like the user redirected to once things are complete.  This can contain any information you wish returned to your endpoint.  If you are passing data as a query string, it is best that the data is URL encoded, especially if it contains any special characters.

    An example using GETURI to set up this redirect URL would be similar to the following:

    // build JSON into stream file or variable using YAJL, or a string, etc.
    jsonData = '{"state_code":"' + %trim(outStateCode) + '",' + 
               '"redirect_url":"https://www.yourpath.com/endpoint?field1=data1&field2=data2..."}';
    
    geturi_resetValues();
    geturi_setValue('gi_uri':'[contact us for endpoint]');
    geturi_setValue('gi_port':'443'); 
    geturi_setValue('gi_ssl':'*YES');
    geturi_setValue('gi_reqmeth':'POST');
    geturi_setValue('gi_conttype':'application/json');
    geturi_setValue('gi_data':jsonData);
    geturi_setValue('gi_sprhead':'*YES');
    geturi_setValue('gi_outtype':'*RETURN');
    
    rc = geturi_call(GetUri_Out:GetUri_Head:GetUri_MsgCd:GetUri_Msg:errMsg);
    response = geturi_getResponseCode(); //ie 500, 200, etc
    
    //load into YAJL example
    docNode = yajl_buf_load_tree(%addr(GetUri_Out:*DATA):     
                  %len(GetUri_Out):yajl_errMsg); 
    
    

    A content-type of application/json is required as well as properly formatted JSON.

    This call will return JSON and either success or error as follows:

    Success:

    {
      "response":"success",
      "state_code":"[the state code you passed in]"
    }

    Error:

    {
      "response":"error",
      "error":"reason for error"
    }

     

g4g_exchangeCodeForToken() - Exchange Your Code for a Token and Set Up User/Service in G4G

After the user has completed the accepting permissions required for G4G through Google, you now need to retrieve the OAuth 2.0 token (as well as other information) so it can be placed in the setup files inside G4G.

// exchange the code for a token and set up in G4G                                                                   
g4g_setValue('id':'bvstone@gmail.com');                            
g4g_setValue('service':'*DRIVE');                                  
g4g_setValue('state_code':outStateCode);                                                          
rc = g4g_exchangeCodeForToken(errMsg);                

As shown, we are sending the account information, the service and the outStateCode returned from g4g_getRegistrationURL() to the g4g_exchangeCodeForToken() function.  This will take the state code (which is NOT the same as the OAuth 2.0 code returned from Google), make a web service call to get the OAuth 2.0 code, then call a Google API to exchange that code for a token, refresh token, and other information.  The user will then be set up in G4G and as long as the account is active, refreshing the token will be taken care of automatically by G4G when calling any of the functions inside of the G4G Addon Libraries.

See the GreenTools for Google Apps (G4G) documentation for a full set of instructions and settable variables for each of these new functions.

As always, please contact us with any questions.


Last edited 05/03/2022 at 12:43:09



Latest Posts:

Calculating the Size of a File Before Base64 Encoding Calculating the Size of a File Before Base64 Encoding
Posted by August 13, 2022
Programming >> RPG Programming
GreenTools for Microsoft Apps (G4MS) v9.12 Now Includes Function to Send Emails using MIME File GreenTools for Microsoft Apps (G4MS) v9.12 Now Includes Function to Send Emails using MIME File
Posted by August 11, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
GreenTools for Google Apps (G4G) v15.20 Now Supports Shortcuts GreenTools for Google Apps (G4G) v15.20 Now Supports Shortcuts
Posted by August 6, 2022
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
GreenTools for Microsoft Apps (G4MS) Groups Admin Authority Instructions GreenTools for Microsoft Apps (G4MS) Groups Admin Authority Instructions
Posted by July 26, 2022
BVSTools >> BVSTools Software Discussion >> GreenTools for Microsoft Apps (G4MS) Specific Discussion
GreenTools for Microsoft Apps (G4MS) v9.10 Now Includes OneDrive Functions that Work With Groups/Shared Drives GreenTools for Microsoft Apps (G4MS) v9.10 Now Includes OneDrive Functions that Work With Groups/Shared Drives
Posted by July 19, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
GreenTools for Google Apps (G4G) v15.10 Now Includes Drive Functions that Work With Shared Drives GreenTools for Google Apps (G4G) v15.10 Now Includes Drive Functions that Work With Shared Drives
Posted by July 15, 2022
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
GreenTools for Microsoft Apps (G4MS) v9.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page GreenTools for Microsoft Apps (G4MS) v9.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page
Posted by July 4, 2022
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
What Objects Should I Omit from Replication to Ensure My License Keys Work on my HA/DR System? What Objects Should I Omit from Replication to Ensure My License Keys Work on my HA/DR System?
Posted by June 27, 2022
BVSTools >> BVSTools Software Discussion
GreenTools for Google Apps (G4G) v15.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page GreenTools for Google Apps (G4G) v15.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page
Posted by May 3, 2022
BVSTools >> BVSTools Announcements >> GreenTools for G Suite (Google Apps) (G4G) Specific Announcements
How Do I Switch From MAILTOOL Plus to GreenTools for Google or Microsoft Office 365? How Do I Switch From MAILTOOL Plus to GreenTools for Google or Microsoft Office 365?
Posted by April 18, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
PTFs Issued for SSL/TLS Issues PTFs Issued for SSL/TLS Issues
Posted by March 12, 2022
IBM Power Systems >> PTF Watch
Google Dropping Support for Google Dropping Support for "Less Secure Apps" May 30th, 2022. What Does This Mean for Your IBM i Email?
Posted by March 4, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Have You Installed a New Version of MAILTOOL and Now Things Are Acting Different?  Check the Command Defaults! Have You Installed a New Version of MAILTOOL and Now Things Are Acting Different? Check the Command Defaults!
Posted by February 28, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Using MAILTOOL Plus on V7R1, or Any OS Using TLS 1.1 or Older Using MAILTOOL Plus on V7R1, or Any OS Using TLS 1.1 or Older
Posted by January 27, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
BVSTools ILE Functions Being Updated to Remove Hashtag (#) from Function Names BVSTools ILE Functions Being Updated to Remove Hashtag (#) from Function Names
Posted by December 30, 2021
BVSTools >> BVSTools Announcements

Reply




Copyright 1983-2020 BVSTools
GreenBoard(v3) Powered by the eRPG SDK, MAILTOOL Plus!, GreenTools for Google Apps, jQuery, jQuery UI, BlockUI, CKEditor and running on the IBM i (AKA AS/400, iSeries, System i).