afosto / yaac

Yet another ACME client: a decoupled LetsEncrypt client
Other
219 stars 84 forks source link

Steps to implement not entirely clear #28

Closed MrMooky closed 3 years ago

MrMooky commented 4 years ago

I'm a bit lost on how to correctly implement this package. I obviously followed the ReadMe section, but am not clear how to fully integrate this into my Laravel app. That's my current code snippet:

$adapter = new Local('data');
$filesystem = new Filesystem($adapter);

$client = new Client([
    'username' => $user->email,
    'fs' => $filesystem,
    'mode' => Client::MODE_STAGING,
]);

$order = $client->createOrder($domain);
$authorizations = $client->authorize($order);

foreach ($authorizations as $authorization) {
    $txtRecord = $authorization->getTxtRecord();
    $txtRecord->getName();
    $txtRecord->getValue();

    DB::table('domain_validations')->updateOrInsert(
        [
            'user_id' => auth()->id(),
            'base_id' => $base->id
        ],
        [
            'domain' => preg_replace("(^https?://)", "", $request->custom_url),
            'cname' => $cnameProperty,
            'txt' => serialize([$txtRecord->getName(), $txtRecord->getValue()]),
            'cname_validated' => 0
        ]
    );
}

This basically creates the order and stores the txt name and value into the database so I can show the users what to enter in their DNS settings. At this point, the page has been refreshed.

My idea of the next step was to wait at least 30 minutes after the user saved this and then call an action via cronjob to verify. But at this point, I have no access to the initial $client instance anymore since this was only created once during the store function above. How can I now access the $client instance from above?

You example just shows if ($client->isReady($order)) { ... but this clearly cannot be in the same function as it is suggested to wait at least 30 minutes (sleep(30)). Any help or tip regarding this would be really helpful.

bakkerpeter commented 4 years ago

Sorry for the delay, but what you are probably missing (it is undocumented) is that you can open a previous order as follows:

//Obtain ID and store it somewhere
$id = $order->getId();

//Load the order by the stored ID
$client->getOrder($id);

Minor: sleep(30) results in 30 seconds, not minutes, of delay.

bakkerpeter commented 3 years ago

also, have a look at: https://github.com/pompy/yaac-ACME-client-implementation