View on GitHub

Silex-jira-oauth-provider

The Silex JIRA OAuth Provider provides a simple mechanism to enable your applicaton to use the Atlassian JIRA REST API without the need of password transmission.

Download this project as a .zip file Download this project as a tar.gz file

Silex JIRA OAuth Provider

The Silex JIRA OAuth Provider provides a simple mechanism to enable your applicaton to use the Atlassian JIRA REST API without the need of password transmission. Instead of using basic authentication an access token is created using JIRAs OAuth interface. This token can then be used with a Guzzle HTTP Client to retrieve, modify and create issues in JIRA.

Prerequisites

In order for the provider to work, you need the following

Installation

You can install the silex jira oauth provider through Composer

composer require bmwcarit/silex-jira-oauth-provider "dev-master"

The provider currently uses the dev-master version of the guzzlehttp/oauth-provider as it contains a necessary bugfix. To be able to pull this version with composer you need to set the minimum stability of your project to "dev":

{
    "minimum-stability": "dev"
}

Usage

Before you can use the provider you need to configure and register it with your silex application. The following code shows the most common configuration options that are necessary:

$app->register(new JiraOAuthServiceProvider(array(
    'base_url' => 'https://www.yourcorp.com/jira/',
    'private_key' => __DIR__ . '/jira.pem',
    'consumer_key' => 'yoursecretkey',
)));

Once the provider is registered your application will have a new controller mounted at /jira. To start the authentication process simple open the route with the name jira-connect. Either you redirect within your code

$app->redirect($app['url_generator']->generate('jira-connect'));

or you add link to your twig templates.

<a href="{{ path('jira-connect') }}">Click here to authenticate with Jira</a>

Once the authentication is successful the provider will redirect to the route with the name home or, if it does not exist, to / of your silex application.

You can alter this behavior by adding a redirect parameter containing the name of a route or an URL, to which the provider should redirect after successful authentication. For example:

$app->redirect($app['url_generator']->generate('jira-connect',
                                        array('redirect' => 'yourroute')));

Or in your twig template:

<a href="{{ path('jira-connect', {redirect: 'yourroute'}) }}">
    Click here to authenticate with Jira</a>

After successful authentication you can use the Atlassian JIRA REST API with the available Guzzle HTTP Client. For example:

$app['jira.oauth.client']->get('rest/api/2/priority');

Configuration Options

License

The silex-jira-oauth-provider is licensed under the MIT license.

Acknowledgment

The initial work is based on the JIRA OAuth PHP examples by Stan Lemon