2017 © Pedro Peláez
 

symfony-bundle redmine_login

Login to symfony using redmine as user provider

image

ekreative/redmine_login

Login to symfony using redmine as user provider

  • Monday, July 24, 2017
  • by mcfedr
  • Repository
  • 3 Watchers
  • 3 Stars
  • 562 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 1 Open issues
  • 21 Versions
  • 0 % Grown

The README.md

Redmine Login

Latest Stable Version License Build Status SensioLabsInsight Coverage Status, (*1)

Install

composer require ekreative/redmine_login

Kernel

new Ekreative\RedmineLoginBundle\EkreativeRedmineLoginBundle()

Parameters

parameters:
    redmine: 'http://www.redmine.org'

Config

ekreative_redmine_login:
    redmine: %redmine%

Routing

ekreative_redmine_login:
    resource: "@EkreativeRedmineLoginBundle/Resources/config/routing.yml"

Security

security:

    providers:
        webservice:
            id: ekreative_redmine_login.provider

    firewalls:
        unsec:
            pattern: ^/login$
            security: false

        secured_area:
            pattern: ^/
            anonymous:
            simple_form:
                authenticator: ekreative_redmine_login.authenticator
                check_path:    login_check
                login_path:    login
                username_parameter: login[username]
                password_parameter: login[password]
            simple_preauth:
                authenticator: ekreative_redmine_login.api_authenticator
            logout:
                path: /logout

    access_control:
        - { path: ^/login, roles: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/, roles: ROLE_REDMINE }

Security

You can secure your own routes using two roles, (*2)

  • ROLE_REDMINE
  • ROLE_REDMINE_ADMIN

Make Request

$projects = json_decode($this->get('ekreative_redmine_login.client_provider')->get($this->getUser())->get('projects.json')->getBody(), true)['projects']

Login as api user

POST /login HTTP/1.1
Content-Type: application/json

{
    "login": {
        "username": "username",
        "password": "password"
    }
}

Response, (*3)

200 OK

{
  "user": {
    "id": 1,
    "username": "username",
    "firstName": "Name",
    "lastName": "Last",
    "email": "user@domin.com",
    "createdAt": "2000-01-01T00:00:00+00:00",
    "lastLoginAt": "2000-01-01T00:00:00+00:00",
    "apiKey": "your_api_key",
    "status": 1
  }
}

Logged in:, (*4)

GET /admin HTTP/1.1
Host: 127.0.0.1:8000
X-API-Key: your_api_key

Custom user class

If you want to use a custom user class then its very easy! There are two ways, (*5)

  • Either override the parameter ekreative_redmine_login.user.class with the name of your own class that extends RedmineUser., (*6)

  • Or override the service ekreative_redmine_login.user_factory with a service that implements RedmineUserFactoryInterface. You will want to do this if you are using Doctrine., (*7)

RedmineUser contains all the annotations for use with Doctrine, so its super simple to store users in the database., (*8)

Api Doc

If you want the api doc to be listed then use NelmioApiDocBundle, (*9)

Kernel

new Nelmio\ApiDocBundle\NelmioApiDocBundle()

Routing

NelmioApiDocBundle:
    resource: "@NelmioApiDocBundle/Resources/config/routing.yml"
    prefix:   /api/doc

Security

Replace the standard unsec, (*10)

unsec:
    pattern: ^/(login$|api/doc)
    security: false

The Versions