Hi Sirs,

can anyone have an idea reagarding lightopenid log-in on Laravel 4.

i want to make a website using google account on log in.

Thanks in advance.

Recommended Answers

All 4 Replies

Hi, you can include it via composer, in your shell write:

composer require lightopenid/lightopenid:dev-master

Or edit composer.json and to require add:

"lightopenid/lightopenid": "dev-master"

And perform composer update from the terminal. I didn't tested, but it should work like this:

Route::get('/openid', function()
{
    $opID = new LightOpenID('yourdomain.tld');
    if( ! $opID->mode)
    {
        $opID->identity = 'https://www.google.com/accounts/o8/id';
        return Redirect::to($opID->authURL());
    }

    elseif($opID->mode == 'cancel')
    {
        return "User has canceled the authentication";
    }

    else
    {
        # validation here
        if($opID->validate())
        {
            return print_r($opID->identity, true);
        }
        else
        {
            return 'Not logged';
        }
    }
});

The above is based on the example-google.php file that you can find into the archive here:

Check also packagist, which is the repository for composer:

Hi Cereal,

what should i put on the controller

Thanks

i already have the log-in form i have a code :

on my controller

<?php

class OpenidController extends BaseController {
public function showlogin()
        {
            return View::make('login');
        }

    }

on my route

<?php

Route::resource('/','OpenidController@showlogin');

my question is where should i place t he code to make it work.

Thanks in advance

Ok, first of all a resource controller is not meant to define a specific method, but a set of actions that will work using RESTful verbs, this means than in your routes.php file you should to change this:

Route::resource('/','OpenidController@showlogin');

to:

Route::resource('/openid','OpenidController');

But I suggest you to use resource controllers for an API application, because a resource controller expects the use of specific methods and HTTP verbs, as defined here:

So, in your routes.php file change the above with:

Route::get('/openid', 'OpenidController@showLogin');
Route::post('/openid', 'OpenidController@postLogin');

And inside your controller:

class OpenidController extends BaseController {

    public function showLogin()
    {
        return View::make('login');
    }

    public function postLogin()
    {
        $opID = new LightOpenID('localhost'); # CHANGE ME

        if(! $opID->mode)
        {
            $opID->identity = 'https://www.google.com/accounts/o8/id';
            return Redirect::to($opID->authURL());
        }

        elseif($opID->mode == 'cancel')
        {
            return "User has canceled the authentication";
        }

        else
        {
            # validation here
            if($opID->validate())
            {
                return print_r($opID->identity, true);
            }
            else
            {
                return 'Not logged';
            }
        }
    }

Inside the login view create a form that will use the POST method:

<!DOCTYPE html>
<html>
<head>
    <title>Open ID</title>
</head>
<body>

    <form method="post" action="/openid">
        <input type="submit" name="login" value="Google log in" />
    </form>

</body>
</html>

Note that the form action is pointing always to /openid.

When you perform a GET request over /openid you will get the form, when instead you perform a POST request you will process postLogin method.

Important Note: the OpenID login method is deprecated by Google and will be removed in few years, more information here:

I don't know if LightOpenID is going to support the new method, as wrote here:

So consider to use another library like OpAuth:

This has already a package for Laravel, but it is for version 3.0, I haven't tested this, so right now I cannot help you much. Before deciding, I suggest you to check on packagist.org if there are other good alternatives.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.