Authentication in Drupal DrupalCamp Spain 2014 About me, @juampy72 - - PowerPoint PPT Presentation

authentication in drupal
SMART_READER_LITE
LIVE PREVIEW

Authentication in Drupal DrupalCamp Spain 2014 About me, @juampy72 - - PowerPoint PPT Presentation

Juampy Novillo Requena Authentication in Drupal DrupalCamp Spain 2014 About me, @juampy72 Drupal 7 and 8 module Developer at Lullabot maintainer and core developer Let's start by defining Authentication and Authorization Authentication


slide-1
SLIDE 1

Authentication in Drupal

Juampy Novillo Requena

DrupalCamp Spain 2014

slide-2
SLIDE 2

About me, @juampy72

Drupal 7 and 8 module maintainer and core developer Developer at Lullabot

slide-3
SLIDE 3

Let's start by defining Authentication and Authorization

slide-4
SLIDE 4

Authentication

Show me your ID, sucker!

slide-5
SLIDE 5

Authorization

403

None shall pass!!

slide-6
SLIDE 6

As the Symfony book states...

http://symfony.com/doc/current/book/security.html

slide-7
SLIDE 7

Authentication in Drupal 8

Drupal 8 implements a Modular Authentication System. Different Authentication Providers may extract a Drupal $user out of a given $request.

slide-8
SLIDE 8

Auth Providers in core

Cookie Returns authenticated or anonymous user depending on the presence of a cookie. Basic Auth Checks if user & password are in the request headers and finds a matching user in the DB.

slide-9
SLIDE 9

Basic Auth example

php > print base64_encode('test:test');

slide-10
SLIDE 10

Cookie auth example

  • 1. Obtain a cookie for a Drupal user.
  • 2. Add the cookie id to the request.

https://drupal.org/node/2076725

slide-11
SLIDE 11

Auth Providers in contrib: OAuth

Supports OAuth 1.0a protocol (Twitter, Flickr). No support for OAuth2 (Facebook) yet :-( Will be implemented at OAuth2 Server

slide-12
SLIDE 12

Oauth setup

slide-13
SLIDE 13

OAuth example request

REQUEST RESPONSE

https://drupal.org/project/guzzle_oauth

slide-14
SLIDE 14

¿How does it work?

slide-15
SLIDE 15

Client

Request /latest-news Authorization: Basic pvcGVuIHNlc2ZQ==

Server

Drupal bootstraps Authentication Manager $request

  • Basic auth.apply()
  • Cookie.apply()

$request Basic Auth.authenticate() $user Access Controllers (EntityaccessController, MenuAccessController...) Build response OK 200

  • DrupalCamp Spain is a total success
  • Geeks in Valencia's Biopark are found

sleeping with the gorilas after a fun night

  • Álvaro Hurtado disappointed the audience

by not doing a striptease TRUE

AUTHENTICATION AUTHORIZATION

slide-16
SLIDE 16

Example: Basic Authentication class

Quick check to see if we can authenticate If the above is TRUE, proceed and attempt to extract a $user.

slide-17
SLIDE 17

Basic authentication service

This makes the class discoverable. Higher priority means that it will try to authenticate before others The Authentication Manager looks for services tagged as authentication_provider

slide-18
SLIDE 18

Loading authentication providers

slide-19
SLIDE 19

Examples

http://hillsidek9academy.com/wp-content/uploads/2013/12/dog-training.jpg

slide-20
SLIDE 20

Authenticate an existing route

friendly_support module Makes it impossible to send support requests by ading HTTP authentication to the Contact form ;D

slide-21
SLIDE 21
  • 1. Extend RouteSubscriberBase

$provider is an identifier for a set of routes. Normally is the module name. Here is where we add authentication rules

slide-22
SLIDE 22
  • 2. Make the class a service
  • Just add event_subscriber tag.
  • RouteSubscriberBase takes care of the rest.

Change record

slide-23
SLIDE 23
  • 3. Install module and open /contact
slide-24
SLIDE 24

We can do it from the route definition.

Authenticate a custom route

Allowed methods: Basic Authentication This is part of Authorization: only authenticated users can access.

slide-25
SLIDE 25

Authenticate a REST resource

Recommended read: REST: exposing data as RESTful web services

slide-26
SLIDE 26

REST UI

REST UI offers site builders an interface to set up a REST API, including output formats and authentication.

slide-27
SLIDE 27

Authenticate a view

slide-28
SLIDE 28

Authenticate a view trough code

slide-29
SLIDE 29

Authenticate a view through the UI

https://drupal.org/node/2228141

slide-30
SLIDE 30

Views authentication example

slide-31
SLIDE 31

How to help?

  • Add flood support to OAuth
  • Implement more Auth

Providers:

○ OAuth2 ○ Digest Authentication ○ IP based authentication

slide-32
SLIDE 32

Thanks! Questions?

about.me/juampy @juampy72