Skip to content

netvlies/NetvliesBasecampBundle

Repository files navigation

NetvliesBasecampBundle

knpbundles.com

Symfony2 bundle around the basecamp-php client. It provides an easy way to integrate the new Basecamp API in your project.

Installation

Use Composer to install the bundle:

$ composer.phar require netvlies/basecamp-bundle

Enable the bunble in your kernel:

// app/AppKernel.php
public function registerBundles()
{
    $bundles = array(
        // ...
        new Netvlies\Bundle\BasecampBundle\NetvliesBasecampBundle(),
    );
}

Configuration

This bundle supports authentication via HTTP authentication (easy and quick) or OAuth (a little bit more difficult).

HTTP authentication

Below is an example of the minimal configuration using HTTP authentication. Only thing you need to do is supply your own credentials.

# app/config/config.yml
netvlies_basecamp:
    authentication: http
    app_name: My Funky Application
    app_contact: http://www.myfunkyapplication.com
    identification:
        user_id: 1234
        username: [email protected]
        password: secret

OAuth authentication

If you have a more advanced use case you probably want to use OAuth. To implement OAuth in your Symfony2 project we recommend the HWIOAuthBundle.

Create an OAuth credentials provider

First start by implementing the Netvlies\Bundle\BasecampBundle\OAuth\CredentialsProviderInterface. Below is an simple example assuming you store the OAuth data in your User entity:

namespace Acme\Bundle\MainBundle\OAuth;

use Netvlies\Bundle\BasecampBundle\OAuth\CredentialsProviderInterface;
use Symfony\Component\Security\Core\SecurityContext;

class BasecampCredentialsProvider implements CredentialsProviderInterface
{
    protected $context;

    public function __construct(SecurityContext $context)
    {
        $this->context = $context;
    }

    public function getBasecampId()
    {
        if (! $this->context->isGranted('IS_AUTHENTICATED_FULLY')) {
            throw new \RuntimeException('Please login before using Basecamp');
        }

        return $this->context->getToken()->getUser()->getBasecampId();
    }

    public function getToken()
    {
        if (! $this->context->isGranted('IS_AUTHENTICATED_FULLY')) {
            throw new \RuntimeException('Please login before using Basecamp');
        }

        return $this->context->getToken()->getUser()->getToken();
    }
}

Now register this as a service:

services:
    acme.basecamp.oauth_credentials_provider:
        class: Acme\Bundle\MainBundle\OAuth\BasecampCredentialsProvider
        arguments: ["@security.context"]

Configure the bundle to use your provider

Finally supply the service id into the bundle configuration like this:

netvlies_basecamp:
    authentication: oauth
    app_name: My Funky Application
    app_contact: http://www.myfunkyapplication.com
    oauth:
        credentials_provider: acme.basecamp.oauth_credentials_provider

Usage

You can now get the client from the container and use it:

$client = $this->get('basecamp');
$project = $client->getProject(array(
    'projectId' => 1
));

About

Symfony2 bundle around the basecamp-php client

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages