Coder Social home page Coder Social logo

mjhwssebundle's Introduction

Intent: Create a WSSE provider, including a Symfony2 client and a vanilla PHP client

Right now, this is basically a direct copy of the Symfony2 Cookbook entry on creating a custom authentication provider.

This is meant to be used for protecting web services on top of Symfony2

#To-do

  • DONE! - Annoying: Can't get final compare of signatures to work... Strings are identical and '===' is returning true, but exception is thrown when the function returns. Returning true manually works fine. Calculating an SHA1 on each one is also identical. This needs to be solved asap. ... ... ... As it turned out, I had forgotten to set the token as authenticated... As a result, the listener was getting called a second time (why?) to validate the new token, which was now sans a timestamp and digest value.

  • DONE! - Format timestamp as UTC

  • DONE! - Handle timezones appropriately when generating / parsing times

  • Provide a mechanism to purge expired nonces

  • DONE! - Handle curl errors better

  • Build full headers for the curl request

  • Provide support for non-curl-enabled installations

  • Provide extras folder with additional clients

    • DONE! - Non-namespaced PHP -- I just stripped the namespace and use off and saved in another file.
    • Ruby
    • Javascript
    • Java
    • These are probably available already, but should be included
  • DONE! ~~ Clean up commented debug stuff - logging, etc.~~

  • DONE! Create getResponse(), hasError(), getError() in the client class

#Installation

###Update Dependencies

[MjhWsseBundle]
    git=http://github.com/mjhapp/MjhWsseBundle.git
    target=/bundles/MJH/WsseBundle

###Update AppKernel.php

new MJH\WsseBundle\MjhWsseBundle(),

###Update autoload.php

'MJH'                            => __DIR__.'/../vendor/bundles',

###Update security.yml - add factory, add user provider, add firewall

security:
    factories:
        - "%kernel.root_dir%/../vendor/bundles/MJH/WsseBundle/Resources/config/security_factories.xml"
providers:
    wsse_provider:
        entity:
            class: Acme\DemoBundle\Entity\User  # This class must implement UserProviderIterface
firewalls:
    wsse_secured:
        pattern: ^/api/.*
        wsse: true
        provider: wsse_provider

###Implement UserProviderInterface on the class that will be providing user accounts to the security system

<?php
class UserRepository extends EntityRepository implements UserProviderInterface
{

    /**
    *
    * The following functions support UserProviderInterfare requirements for WSSE
    *
    */

    public function loadUserByUsername($username)
    {
        $user = $this->findOneBy(array('auth_token' => $username));

        return $user;
    }

    public function refreshUser(UserInterface $user)
    {
        return $this->loadUserByUsername($user->getAuthToken());
    }

    public function supportsClass($class)
    {
        return $class === 'Acme\DemoBundle\Entity\User';
    }
}

#Client Usage

###PHP

<?php
// SecuredController.php


namespace Acme\DemoBundle\Controller;

...
use MJH\WsseBundle\Security\Authentication\Request\WsseRequest;
...


class SecuredController extends Controller
{

    public function indexAction(Request $request)
    {
        ...
        $wsseRequest = new WsseRequest('http://theapp.nut/api/v1/getsome.php', null, 'mjhapp','secret');

        $wsseRequest->sendRequest();

        if ( $wsseRequest->hasError() )
        {
            $errortext = $wsseRequest->getError();
            $errorcode = $wsseRequest->getErrorCode();
        }
        else
        {
            $response = $wsseRequest->getResult();
        }

        return array(
           ...
         );
    }
}

mjhwssebundle's People

Contributors

mjhapp avatar marshall-at-corvee avatar

Stargazers

Yıldıray Ünlü avatar Geoff Oslund avatar Patrik Patie Gmitter avatar  avatar Rich Sage avatar Irmantas Šiupšinskas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.