Bellots
Bellots

Reputation: 1773

Fabric Digits oauth authentication in PHP

I've got an app which works with Digits as authentication. Client-side works perfectly, but I'm not able to make the server user authentication through oAuth. My server is developed with Laravel, so it's PHP. My endpoint is under https, so everything should be ready to make the call.

Upvotes: 1

Views: 598

Answers (1)

Bellots
Bellots

Reputation: 1773

I solved by myself!

Here's the code that makes correctly the authentication through Digits O-Auth.

The function that makes authentication is inside an AuthManager class and I call in this way:

$obj = AuthManager::verifyUser($request->header('X-Auth-Service-Provider'),$request->header("X-Verify-Credentials-Authorization"));

And here's the function that makes the magic:

public static function verifyUser ($xAuthServiceProvider, $xVerifyCredentialsAuthorization)
{

    $curl = curl_init();
    curl_setopt($curl,CURLOPT_URL, $xAuthServiceProvider);
    curl_setopt($curl,CURLOPT_HTTPHEADER, array(
        'Content-length: 0',
        'Content-type: application/json',
        'Authorization: '.$xVerifyCredentialsAuthorization,
    ));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);

    $content = curl_exec($curl);
    $info = curl_getinfo($curl);
    curl_close($curl);
    $obj = json_decode($content, true);

    return $obj;
}

If you have any problem, don't hesitate to write here!

EDIT WITH EXAMPLE FUNCTION ABOUT HOW TO GET DATA FROM O-AUTH

public function authenticate (Request $request)
{

    $obj = AuthManager::verifyUser($request->header('X-Auth-Service-Provider'),$request->header("X-Verify-Credentials-Authorization"));
    if(isset($obj["errors"]))
    {
        return "error!";
    }
    $digits_token =  $obj["access_token"]["token"];
    $digitsId = $obj["id"];


    /*
        the variables above are returned by O-auth server-server authentication
    */
}

Upvotes: 3

Related Questions