Sharepoint Online Authentication with Play Framework web application (Scala)

We are trying to connect our Play framework application with the Sharepoint Online site collection. As per the ADAL libraries these are JAVA based and we are unable to use these libraries in the Play framework (based on Scala language).


  1. What are the options available to authenticate the Scala web application with share point online portal? Kindly suggest us the ways to connect play framework web app with Azure AD, so we will be able to view sharepoint data over the internet

  2. Can we configure the SharePoint site collection to only allow the access based on a either a user or an IP Address ?


Play Framework has a Java API which you can use so you can use Java libraries. But Scala is also compatible with Java anyway so you can use Java libraries from Scala.

Thanks for your reply, can i have a sample for using Java libraries inside scala. or if we get sample for connecting share point online from Play framework scala code would be great.

Here’s Scala documentation on Java interop:

Play uses sbt for building or you can use Gradle. Here’s sbt documentation on adding a library:

But if you don’t know Scala, then just use Java. Take a look at the Play docs and read “Getting Started” and “Play for Java developers”.

We have a several play projects, that authorizes against Azure ADs, using the ADAL4J libraries from scala code.

Since its customer projects, I cant share the code. But from scala, you can just do something like this:

var service: java.util.concurrent.ExecutorService = java.util.concurrent.Executors.newFixedThreadPool(1)
var context: AuthenticationContext = new AuthenticationContext(AUTHORITY, false, service)
var result: java.util.concurrent.Future[AuthenticationResult] = context.acquireToken("", CLIENT_ID, username, password, null)

AUTHORITY and CLIENT_ID beeing specific to the AD you are trying to authorize against.

This will give you you an AuthenticationResult in a java.util.concurrent.Future. Which isn’t directly compatible with the scala.concurrent.Future type. So you need to handle that the java way. But the that being said, it works very well in our projects.

Another path is that you those an authentication library like play-sillhouette or pac4j library, for handling authorization. They provide a bit more thorough solutions, and authorization actions you can use directly in your code.

1 Like