Skip to main content
Skip table of contents

OAuth authorization failed

With the new Salesforce release of Enhanced Domain, many Sandbox organizations have been receiving an Error Message when trying to compose documents with custom buttons or links. The error message is “OAuth authorization failed: LOGIN_ERROR_RESTR_DOMAIN”

Please refer to the following steps to resolve this in your Sandbox org.

1. Create a new Visualforce page

The Visualforce page, to which the Dynamo button points to, needs to be changed. If the button is currently connected to a default Visualforce page (managed by Documill Dynamo package), a new Visualforce page should be created. This can be done from Setup → Custom code → Visualforce pages → New. Some value for label must be given, for example, NewDynamoFrame. The option “Available for Lightning Experience, Experience Builder sites, and the mobile app” should be selected and the following markup pasted into the markup field:

CODE
<apex:page applyBodyTag="false" controller="DynamoFrameController">
 <apex:stylesheet value="https://dynamo.documill.com/visualforce/dynamo-vf.css" />
  <apex:includeScript value="{!$Resource.dynamo__DynamoFrameScript}" />
  <head></head>
  <body>
   <div class="dynamo-container">
   <div class="dynamo-loading"></div>
   <apex:iframe width="100%" height="100%" src="https://dynamo-eu1.documill.com/service/sfdco?useFlow=true&customListenerURL=*&serverURL={!ServerURL}&id={!$CurrentPage.parameters.id}&templateID={!$CurrentPage.parameters.templateID}&oauthLoginURL={!DomainStr}/&sfEnvironment={!Environment}"></apex:iframe>
   </div>
   <script>initDynamoVisualforce("/{!$CurrentPage.parameters.id}");</script>
  </body>
</apex:page>

2. Create an Apex Class to retrieve org information automatically

New Apex class can be created from Setup → Custom code → Apex classes → New. Following Apex class should be pasted into the Apex class field:

CODE
/**
    Controller class for DynamoFrame VF page
*/
public class DynamoFrameController {

    /** Get organization domain */
    public static System.Url getDomain() {
        return System.Url.getOrgDomainUrl();
    }
    
    /** Get organization domain as String */
    public static String getDomainStr() {
        return getDomain().toExternalForm();
    }
    
    /** Get server URL */
    public static String getServerURL() {
        return getDomainStr() + '/services/Soap/u/58.0';
    }
    
    /** Get Salesforce environment (sandbox / production) */
    public static String getEnvironment() {
        System.Domain domain = System.DomainParser.parse(getDomain());
        return domain.getSandboxName() == null ? 'production' : 'sandbox';
    }
}


3. Change the custom button(s)

The custom button(s) should be edited so that it points to the newly created VF page instead of the old one. Setup → Object manager → Object with the custom button → Buttons, Links and Actions → The custom button. Old: /apex/dynamo__DynamoFrame?id={!Opportunity.Id}&sfEnvironment=sandbox

-> New: /apex/nameOftheNewVFPage?id={!Opportunity.Id}. The nameOftheNewVFPage should be replaced with the label value given for the new VF page in the first step. The sfEnvironment parameter is not required anymore as it comes from the new Apex class. If it’s not possible to edit the existing button as it’s also part of the package, a new one must be created. From Setup → Object manager → Object with the custom button → Buttons, Links and Actions → New button or link. Select the Display type as Detail Page Button and the Behavior as Display in existing window without sidebar and paste /apex/nameOftheNewVFPage?id={!Opportunity.Id} into the text field. The nameOftheNewVFPage should be replaced with the label value given for the new Visualforce page in the first step. Please refer to this article for further instruction to create buttons.

Please contact support@documill.com if you still receive errors after implementing these.

Test class for the controller

CODE
/**
    Test class for DynamoFrameController. 
    
    The tests make sure that all DynamoFrameController operations succeed in the organization. 
    No result validation is done as the tested methods mainly call native Apex methods and contain 
    very little custom logic.
*/
@isTest
public class DynamoFrameControllerTest {

    @isTest static void getDomain() {
        System.Url domain = DynamoFrameController.getDomain();
        Assert.isNotNull(domain);
    }
    
    @isTest static void getDomainStr() {
        String domainStr = DynamoFrameController.getDomainStr();
        Assert.isNotNull(domainStr);
    }
    
    @isTest static void getServerURL() {
        String serverURL = DynamoFrameController.getServerURL();
        Assert.isNotNull(serverURL);
    }
    
    @isTest static void getEnvironment() {
        String sfEnv = DynamoFrameController.getEnvironment();
        Assert.isNotNull(sfEnv);
    }
}
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.