3

I have created a RESTful apps using Lithium php framework and now my question is how to secure it?

Is there any existing code for OAUTH or HTTP Digest Authentication that uses lithium framework?

hakre
  • 193,403
  • 52
  • 435
  • 836
John Laniba
  • 435
  • 3
  • 12
  • What does this even mean? What kind of security? Cookies, API tokens, auth, access control? Lithium is a framework, it provides tools and structure, but also (out of necessity) assumes you're a programmer who knows how to write software. Sorry, but this question is meaningless. – Nate Abele Dec 08 '12 at 15:41
  • Sorry if its not clear but I mentioned REST application it means Oauth or Http Digest Authentication. I want to know if there's any existing code for OAUTH or Digest Authentication in lithium? – John Laniba Dec 09 '12 at 13:51

2 Answers2

2

While I'm not sure what sort of security you are looking for ...

There is built in security for Lithium, you can see two short tutorials to get you going here:

The basics are covered in the "Simple Authentication" tutorial ... you'll need:

  • A database to keep track of you users
  • Bootstrap Auth via config/bootstrap.php
  • Setup Sessions & Auth adapters

Then it depends on if you are going to do authenticaion via forms, or by some other method.

The turtorials will show you how to setup a form, but you can also "secure" the route (url) that is being requested via the config/routes.php file like so ...

<?php

use lithium\net\http\Router;
use lithium\core\Environment;

use lithium\security\Auth;

// check if the user is logged in
$user = Auth::check('default'); 

// these routes are not behind a login
Router::connect('/login', 'Sessions::add');
Router::connect('/logout', 'Sessions::delete');

if ($user && $user["user"] == "admin") {

    // these two routes will only work if a user is authenticated.
    Router::connect('/{:controller}/{:action}/{:args}.{:type}');
    Router::connect('/{:controller}/{:action}/{:args}');
}

// redirect the user to a login if no other routes match
Router::connect('/{:args}', array(), function($request) { header('Location: /login/url/'.str_replace('/','*',$request->url)); exit; });

?>
dakdad
  • 2,947
  • 2
  • 22
  • 21
Justin Jenkins
  • 26,590
  • 6
  • 68
  • 1,285
2

Thanks for editing your question to actually ask something specific. Please see the following:

dakdad
  • 2,947
  • 2
  • 22
  • 21
Nate Abele
  • 5,771
  • 32
  • 27