oauth 2.0 – How to fix 401 – unauthorized – when testing spring rest API secured with google oauth2 via postman – roles in DB – Code Utility


I was following this articles


I want to test the spring endpoints via postman, and setup below and getting token, but not sure of the roles. The roles are in DB

How can I test my rest api using postman

My endpoint is like below

    public List<CourseDTO> list(@CurrentUser LocalUser user) {
        return myService.findAll();

Websecurity config

.antMatchers(“/”, “/error”, “/api/all”, “/api/auth/“, “/oauth2/“,
“/index.html”, “/.js”, “/.js.map”, “/.css”, “/assets/img/.png”,

though I tried .antMatchers(HttpMethod.POST, "/admin/todo/**").hasRole("ADMIN")

But getting 401 unauthorized – “message”: “Full authentication is
required to access this resource”,

enter image description here


Set it like this and then retry :