Skip to content

Laravel + tappleby auth token package - Separate controllers? #54

Open
@tjmahaffey

Description

@tjmahaffey

I'm building a Laravel app which also includes an API. I'd like to extend the default Laravel auth scheme to allow api access via tokens. Same auth structure, but two vehicles: api users validated via tokens, web app users validated via Laravel's default auth scheme.

I have a SessionController which I use to login and log out for web app users:

<?php

class SessionController extends \BaseController {

public function create() {

    if (Auth::check()) {
        return Redirect::to('/post/dashboard');
    }
    return View::make('sessions.create');

}

public function store() {

    if ( Auth::attempt(Input::only('username', 'password')) ) {
        return Redirect::to('/post/dashboard');
    } else {

        return Redirect::to('/login')->with('error', 'Failed Auth.');
    }

}

public function destroy() {

    Auth::logout();
    return Redirect::route('login');
}

}

Is it preferred that the api users go through a wholly separate controller for authentication in order to generate and validate tokens? Or can I somehow add the tappleby auth token stuff inside my existing SessionsController and have it serve both purposes?
I'm interested in best practices here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions