jhipster oauth2 client secret

Andy Verbunt

I've been experimenting with jhipster. I've configured my app to work with oauth2. For that purpose I have a client secret in my application.yml

According to several articles I have found on this topic, the client secret should be kept secret at all times. For example, check https://aaronparecki.com/articles/2012/07/29/1/oauth2-simplified

The client secret must be kept confidential. If a deployed app cannot keep the secret confidential, such as Javascript or native apps, then the secret is not used.

I've noticed though that the generated auth.oauth2.service.js contains the secret in plain text:

        return {
            login: function(credentials) {
                var data = "username=" + credentials.username + "&password="
                    + credentials.password + "&grant_type=password&scope=read%20write&" +
                    "client_secret=mySecretOAuthSecret&client_id=myapp";
                return $http.post('oauth/token', data, {
                    headers: {
                        "Content-Type": "application/x-www-form-urlencoded",
                        "Accept": "application/json",
                        "Authorization": "Basic " + Base64.encode("myapp" + ':' + "mySecretOAuthSecret")
                    }
                }).success(function (response) {
                    var expiredAt = new Date();
                    expiredAt.setSeconds(expiredAt.getSeconds() + response.expires_in);
                    response.expires_at = expiredAt.getTime();
                    localStorageService.set('token', response);
                    return response;
                });
            },

I understand that it will be a little bit harder to find in the minified javascript, but anyone looking for 'client_secret' will be rewarded quickly.

Am I missing something? Or is the jHipster oauth implementation unsafe?

Thanks, Andy

sdoxsee

Since a JS client like jhipster's can't keep the client-secret "secret", it doesn't make sense to use the client-secret at all. The OAuth2 Resource Owner Password Credentials Grant flow that jhipster uses is for very trusted clients--which the client side of jhipster is. It allows for you to skip the normal "authorize" endpoint and go directly to the "token" endpoint to get your tokens with your user credentials. If your Spring Authorization Server (AS) defines a client-secret, you'll need to pass that secret along from the client JS. However, if you remove the secret definition from your in-memory client setup in your AS (e.g. comment out that line in OAuth2ServerConfiguration.java), you can leave it out altogether in your JS (see below)

return {
   login: function(credentials) {
      var data = "username=" + credentials.username + "&password=" + credentials.password + "&grant_type=password&scope=read%20write&";
      return $http.post('oauth/token', data, {
         headers: {
            "Content-Type": "application/x-www-form-urlencoded",
            "Accept": "application/json",
            "Authorization": "Basic " + Base64.encode("myapp" + ':' + "")
         }
      }).success(function (response) {
         var expiredAt = new Date();
         expiredAt.setSeconds(expiredAt.getSeconds() + response.expires_in);
         response.expires_at = expiredAt.getTime();
         localStorageService.set('token', response);
         return response;
      });
   },

After removing your client-secret, I don't think your app is really any safer but it feels a bit cleaner and honest--in that you're acknowledging that using a JS-only client, you can only be so safe. For JS and native clients, the implicit flow is typically used and it doesn't bother with a client-secret. It's simplified from the more robust authorization code grant flow for the fact that with a JS or native client can't keep a secret.

Anyway, jhipster probably shouldn't have the client-secret in the JS source but I don't believe it's doing any harm (since the only alternative is to have a blank client-secret which isn't any more secure). You're not unsafe (as the spec allows for this kind of thing) but you'd be safer using the authorization code flow (which would require a little work in the jhipster implementation) or to have a light server proxy add the client-secret to the request to the "token" endpoint rather than from the JS directly. Server to server communication (e.g. via a proxy) keeps secrets away from the view of the browser.

see this post for a nice discussion of the pitfalls of a JS-only client with oauth2: http://alexbilbie.com/2014/11/oauth-and-javascript/

here's an example of using oauth2 with angularjs and spring over a proxy: https://spring.io/blog/2015/02/03/sso-with-oauth2-angular-js-and-spring-security-part-v

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Tools for OAuth2 without client secret

From Dev

Security of OAuth2 Client Id and Client Secret

From Dev

OAuth2 client_secret column not allowed to be null

From Dev

Client secret + refreshing the access token in spring oauth2

From Dev

How to generate Client Secret in OAuth2 Authentication using Spring

From Dev

oauth2 client_secret from my gmail account?

From Dev

can not find client Secret on google OAUTH2

From Dev

OAuth2 - how to authorize without client secret?

From Dev

Difference between client_id and client_secret OAuth2 &OAuth flows types

From Dev

Difference between client_id and client_secret OAuth2 &OAuth flows types

From Java

client secret in OAuth 2.0

From Dev

OAuth2 Server setup 'client_id' ad ''client_secret' for 'password' grant type

From Dev

OAuth2 Password Grant Type with Client_Id & Client_Secret

From Dev

Oauth2 & Laravel - `Client_id` & `Client_secret` - where to place, store, call?

From Dev

Is it possible to retrieve an OAuth2 access token from Google with client secret file of Google Apps Script project?

From Dev

How to keep the oAuth 2.0 Client Secret a secret?

From Dev

How to keep the oAuth 2.0 Client Secret a secret?

From Dev

oauth2 get access token via db by supplied client id/secret for trusted 3rd party client

From Dev

SpringBoot OAuth2: Purpose of the .secret() function?

From Dev

Understanding Client in OAuth2

From Dev

Useless client_secret in OAuth v2

From Dev

Why isn't client secret encrypted in OAuth?

From Dev

Google OAuth - Keeping the Client ID Secret

From Dev

Oauth 2.0 client secret on GitHub [CLI app]

From Dev

Google OAuth - Keeping the Client ID Secret

From Dev

Understanding the need of client id, client secret in oauth 2.0

From Dev

Ionic + Jhipster oauth2 Error No Access-Control

From Dev

How to perform actions on successful login via OAuth2 in jhipster

From Dev

Controlling authentication redirects with JHipster, Spring Security, and oauth2

Related Related

  1. 1

    Tools for OAuth2 without client secret

  2. 2

    Security of OAuth2 Client Id and Client Secret

  3. 3

    OAuth2 client_secret column not allowed to be null

  4. 4

    Client secret + refreshing the access token in spring oauth2

  5. 5

    How to generate Client Secret in OAuth2 Authentication using Spring

  6. 6

    oauth2 client_secret from my gmail account?

  7. 7

    can not find client Secret on google OAUTH2

  8. 8

    OAuth2 - how to authorize without client secret?

  9. 9

    Difference between client_id and client_secret OAuth2 &OAuth flows types

  10. 10

    Difference between client_id and client_secret OAuth2 &OAuth flows types

  11. 11

    client secret in OAuth 2.0

  12. 12

    OAuth2 Server setup 'client_id' ad ''client_secret' for 'password' grant type

  13. 13

    OAuth2 Password Grant Type with Client_Id & Client_Secret

  14. 14

    Oauth2 & Laravel - `Client_id` & `Client_secret` - where to place, store, call?

  15. 15

    Is it possible to retrieve an OAuth2 access token from Google with client secret file of Google Apps Script project?

  16. 16

    How to keep the oAuth 2.0 Client Secret a secret?

  17. 17

    How to keep the oAuth 2.0 Client Secret a secret?

  18. 18

    oauth2 get access token via db by supplied client id/secret for trusted 3rd party client

  19. 19

    SpringBoot OAuth2: Purpose of the .secret() function?

  20. 20

    Understanding Client in OAuth2

  21. 21

    Useless client_secret in OAuth v2

  22. 22

    Why isn't client secret encrypted in OAuth?

  23. 23

    Google OAuth - Keeping the Client ID Secret

  24. 24

    Oauth 2.0 client secret on GitHub [CLI app]

  25. 25

    Google OAuth - Keeping the Client ID Secret

  26. 26

    Understanding the need of client id, client secret in oauth 2.0

  27. 27

    Ionic + Jhipster oauth2 Error No Access-Control

  28. 28

    How to perform actions on successful login via OAuth2 in jhipster

  29. 29

    Controlling authentication redirects with JHipster, Spring Security, and oauth2

HotTag

Archive