Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call JHipster (Spring) OAuth2 Rest server using Postman Authentication helpers

Postman has Authentication helpers to help with authenticated calls and I'm trying to use the OAuth 2.0 helper to call a REST server created by JHipster using Spring (Security, Social, etc).

I've tried a lot of configurations, this is the screen (client ID and Secret were masked):

Auth helper Configuration

For the Authorization URL I've tried:

  • http://127.0.0.1:8080/oauth/authorize
  • http://127.0.0.1:8080/#/login (the app's login route)

The closer I get from receiving a token back to Postman is:

Response failed

I don't know why it's erring like this. Maybe I'm setting the Callback URL incorrectly? Do I need to do this in the server or in the client (AngularJS)?

Does anyone have any idea of what's wrong? I appreciate your help.

like image 507
Denis C de Azevedo Avatar asked Jan 06 '16 04:01

Denis C de Azevedo


1 Answers

To build on @sdoxsee's answer:

Currently (August 2017) JHipster generates a class called UaaConfiguration with the configure(ClientDetailsServiceConfigurer) method setting up the client ID, client secret, scope and grant type. Refer to these settings (including the referenced JHipster properties in the application*.yml) to populate the Postman authentication helper, using /oauth/token as both Auth URL and Access Token URL.


Example:

@Override                                                                                                     
public void configure(ClientDetailsServiceConfigurer clients) throws Exception {                              
    /*                                                                                                        
    For a better client design, this should be done by a ClientDetailsService (similar to UserDetailsService).
     */                                                                                                       
    clients.inMemory()                                                                                        
        .withClient("web_app")                                                                                
        .scopes("openid")                                                                                     
        .autoApprove(true)                                                                                    
        .authorizedGrantTypes("implicit", "refresh_token", "password", "authorization_code")                  
        .and()                                                                                                
        .withClient(jHipsterProperties.getSecurity().getClientAuthorization().getClientId())                  
        .secret(jHipsterProperties.getSecurity().getClientAuthorization().getClientSecret())                  
        .scopes("web-app")                                                                                    
        .autoApprove(true)                                                                                    
        .authorizedGrantTypes("client_credentials");                                                          
}  

And,

jhipster:
    security:
        client-authorization:
            client-id: internal
            client-secret: internal

Means your authentication helper should be populated as follows:

Postman Authentication Helper

like image 61
Niel de Wet Avatar answered Oct 21 '22 18:10

Niel de Wet