bvstone

GreenTools for Microsoft Apps (G4MS) v9.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page

Posted:

GreenTools for Microsoft Apps (G4MS) v9.00 Now Offers Functions to Bypass Registration Command and BVSTools Landing Page

With GreenTools for Microsoft Apps (G4MS) v9.00 and up you are now able to complete service registration for accounts using ILE functions instead of the G4MSREGSVC 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.  This is similar to the changes made to GreenTools for Google Apps (G4G) recently.

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:

g4ms_getRegistrationURL() - Retrieve the Microsoft Registration URL

// get a unique Code and URL 
g4ms_setValue('id':'bvstone@outlook.com');                            
g4ms_setValue('service':'*ONEDRIVE365');
rc = g4ms_getRegistrationURL(outStateCode:outURL:errMsg);     

Once this is called, the g4ms_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 Microsoft.  This code will also be used for URL redirection should you require that.
  2. outURL - This is a direct link URL to Microsoft where the user will sign into their Microsoft Account and authorize G4MS 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 Microsoft 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 g4ms_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"
    }

     

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

After the user has completed the accepting permissions required for G4MS through Microsoft, 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 G4MS.

// exchange the code for a token and set up in G4MS                                                                   
g4ms_setValue('id':'bvstone@outlook.com');                            
g4ms_setValue('service':'*ONEDRIVE365');                                  
g4ms_setValue('state_code':outStateCode);                                                          
rc = g4ms_exchangeCodeForToken(errMsg);                

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

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

As always, please contact us with any questions.




Latest Posts:

BVSTools Releases Send Job Log to BVSTools (SNDLOG2BVS) Command BVSTools Releases Send Job Log to BVSTools (SNDLOG2BVS) Command
Posted by August 28, 2023
BVSTools >> BVSTools Announcements
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

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