Jump to content

Provisioning Modules - Single Sign-On


Recommended Posts

I have followed all the setups mentioned on this link (https://developers.whmcs.com/provisioning-modules/single-sign-on/) to implement Service Single Sign-On for Provisioning Module.

Here is our MetaData function:

function mymodule_MetaData() {
    return array(
        "DisplayName" => "MyModuleName",
        "APIVersion" => "1.1",
        "RequiresServer" => false,
        "ServiceSingleSignOnLabel" => "Login to Dashboard",
        "AdminSingleSignOnLabel" => "Login to Dashboard",
    );
}

Here is the ServiceSingleSignOn function!

function mymodule_ServiceSingleSignOn(array $params) {
    try {
        //ExternalAppTypeID
        $queryParams = array(
            "expiresIn" => "432000",    //5 days
        );

        $objAPICredentials = new APICredentialsHelper(null, null);
        $isLoaded = $objAPICredentials->fetch();

        if ($isLoaded) {
            $apiClient = new ApiClient($objAPICredentials->PartnerID, $objAPICredentials->PrivateAPIKey, "v2");
            $jsonResponse = $apiClient->post("/login", $queryParams, $params);

            return array(
                "success" => true,
                "redirectTo" => $jsonResponse->continueUrl, //I tried hardcoding this URL but getting same error!
            );  
        }
        else {
            throw new Exception("Addon Module Configuration Exception: Invalid APIKey.");
        }
    }
    catch (Exception $ex) {
        logModuleCall('MyModule', "ServiceSingleSignOn", $params, $ex->getMessage(), $ex->getTraceAsString());

        return array(
            "success" => false,
            "errorMsg" => $ex->getMessage(),
        );
    }
}

When user clicks on the "Login to Dashboard" button then following error is throw!

Module Command Error
Server ID not found.

We have mentioned RequiresServer = false in MetaData function and our product doesn't need server to be provisioned!

Thank you in advance!

Service-SSO-Error.png

Link to comment
Share on other sites

  • 1 year later...

This appears to be a bug in WHMCS. I'm getting the same behavior you're describing here.

Here's some other project that apparently faced the same issue:

https://github.com/krystal/katapult-whmcs/issues/18

They mentioned a workaround by creating a "blank" server. I'm not super familiar with WHMCS yet so I wasn't sure what they meant by that, but this is what I did (and it worked):

  • Set "RequiresServer" to "true" (since it's busted when it's false)
  • Create a new server (System settings > servers > Add New Server)
  • Select the module you're working on (shows up in the list after you set "RequiresServer" to "true")
  • Set the IP address to "127.0.0.1", click "test connection".
  • Set name to anything you want

With that workaround in place, the SSO started working for me. Kind of annoying that everyone that uses the module will need to add a "blank" server like this though. It'd be nice if this bug was fixed. I've reported it to WHMCS.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated