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:

MAILTOOL Now Allows Email Redirection for Development and Testing MAILTOOL Now Allows Email Redirection for Development and Testing
Posted by May 27, 2023
BVSTools >> BVSTools Announcements >> eMail Tool (MAILTOOL) Specific Announcements
GreenTools for Microsoft Apps (G4MS) Now Supports Footers When Sending Email GreenTools for Microsoft Apps (G4MS) Now Supports Footers When Sending Email
Posted by March 29, 2023
BVSTools >> BVSTools Announcements >> GreenTools for Microsoft Apps (G4MS) Specific Announcements
QuickBooks Online - Subtotals and Discounts Frustration QuickBooks Online - Subtotals and Discounts Frustration
Posted by March 16, 2023
QuickBooks >> QuickBooks Online
Making the Switch From QuickBooks Desktop to QuickBooks Online - No Picnic Making the Switch From QuickBooks Desktop to QuickBooks Online - No Picnic
Posted by March 16, 2023
QuickBooks >> QuickBooks Online
BVSTools Software Verified on V7R5 and Power10 BVSTools Software Verified on V7R5 and Power10
Posted by December 9, 2022
BVSTools >> BVSTools Announcements
Microsoft Office 365 Servers and Random Errors Issue Microsoft Office 365 Servers and Random Errors Issue
Posted by November 14, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Sending/Resending Emails Using a MIME File with MAILTOOL Sending/Resending Emails Using a MIME File with MAILTOOL
Posted by November 8, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Sending an HTML Email on Your IBM i Using MAILTOOL Sending an HTML Email on Your IBM i Using MAILTOOL
Posted by November 1, 2022
BVSTools >> BVSTools Software Discussion >> Email Tools (MAILTOOL) Specific Discussion
Transferring License Keys from One System to Another Transferring License Keys from One System to Another
Posted by October 31, 2022
BVSTools >> BVSTools Software Discussion
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

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).