Reputation: 101
I have created the jhipster demo app and want to check my adapted rest api with a tool like postman. I have tried with Basic Auth and user and password both set to admin, user or system. But none of them can access, getting an 401.
Would be nice if you could give me a hint what to do to access it.
Cheers Markus
Upvotes: 2
Views: 4304
Reputation: 61
If you are using Oauth2 with jhipster, you need to setup Oauth2 token config in postman and get a token before sending a request.
Once your request is successful you will get JsessionID in cookies, use cookies next time and turn the Auth to no auth. Then the cookies will work for you.
Upvotes: 2
Reputation: 6342
Because Postman is now a separate app (instead of an extension), it can't access your cookies directly. However, it's still possible to use Postman with a session-auth JHipster app.
/api/authentication
for the Set-Cookie headers (JSESSIONID and X-XSRF-TOKEN). You can also find the cookies elsewhere in the browser's developer console, in Chrome they are under the Application tab.JSESSIONID
and X-XSRF-TOKEN
cookies. The "Cookies" tab for the request will look like the image below.For help with Postman and JWT auth, see this answer.
Upvotes: 5
Reputation: 1999
My site allows unauthenticated users to access certain section. Thus I find the 401 error annoying.
I made a pull request to fix it, see here: https://github.com/jhipster/generator-jhipster/pull/2623
It requires access to api/account but there are also some other changes to do to avoid a NPE.
Upvotes: 0
Reputation: 1012
In file SecurityConfiguration.java changing from
.antMatchers("/api/**").authenticated()
to
.antMatchers("/api/**").permitAll()
lets you access the api without any authentication.
Note: This is unsecure and makes your API public, but may be usefull while testing via postman.
Upvotes: 2
Reputation: 4681
Just a guess, but the demo app uses cookies and therefore is using CSRF. So you'd need to send the proper CSRF token along with your requests. If you generate the app using a token approach (rather than cookies) you don't need CSRF.
See https://github.com/jhipster/generator-jhipster/issues/363 and search for postman on the page.
Upvotes: 0