O'Reilly logo

Play Framework Cookbook - Second Edition by Giancarlo Inductivo, Alexander Reelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Securing API endpoints with HTTP basic authentication

In this recipe, we will explore how to secure API endpoints using the HTTP basic authentication scheme with Play 2.0. We will use the Apache Commons Codec library for Base64 encoding and decoding for this recipe. This dependency is implicitly imported by Play and we will not need to explicitly declare it to our library dependencies in build.sbt.

How to do it…

For Java, we need to perform the following steps:

  1. Run the foo_java application with Hot-Reloading enabled:
        activator "~run"
    
  2. Create a new play.mvc.Security.Authenticator implementation class in foo_java/app/controllers/BasicAuthenticator.java with the following content:
     package controllers; import org.apache.commons.codec.binary.Base64; import ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required