Configuration error[Application secret not set]
Asked Answered
O

2

3

I got this error running Play 2.4 server in production mode:

play.api.UnexpectedException: Unexpected exception[ProvisionException: Unable to provision, see the following errors:

1) Error in custom provider, @6mh5cjo5l: Configuration error
  while locating play.api.libs.CryptoConfigParser
  while locating play.api.libs.CryptoConfig

...

Caused by: play.api.PlayException: Configuration error[Application secret not set]

How to fix?

Orwin answered 22/6, 2015 at 13:30 Comment(0)
O
8

The default Play template uses the following:

play.crypto.secret="changeme"

in the application.conf which needs to be changed for use in production. Play provides an utility to generate a random secret for you:

./activator playGenerateSecret

with which you can then populate as an environment variable:

APPLICATION_SECRET=...

and in conf/application.conf ensure the following:

play.crypto.secret="changeme"
play.crypto.secret=${?APPLICATION_SECRET}

which as the Play documentation explains:

The second line in that configuration sets the secret to come from an environment variable called APPLICATION_SECRET if such an environment variable is set, otherwise, it leaves the secret unchanged from the previous line.

Then the error will go away.

Orwin answered 22/6, 2015 at 13:30 Comment(1)
Man, you're genius. I was fixing this problem for about 10hours... I'm deploying an app on Heroku and had internal errors without setting crypto.key to a different one. Use "./activator playGenerateSecret" to generate one from your project folder. Thank you !!!Nonpartisan
G
0

For anyone that can still stumble upon this issue and is not using activator yet sbt as I am.

Just follow the documentation on Play 2.x page (Play 2.4 example)

The "magic" command is

sbt playUpdateSecret

This will both generate the secret and update your conf file. So this command saved me a lot of work and discovering.

Cheers.

Gatefold answered 5/3, 2020 at 10:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.