简体   繁体   中英

Spring Security Authentication with REST API?

I have a Grails backend that provides a REST api. My mobile app accesses this REST Api to obtain data from the server. The authentication, login and logout should be done with Spring Security.

This works great for Desktop users because I serve the pages that I build on my server.

How do I have to use Spring Security for my REST Controller to get the authentication, login and logout working?

If you're providing a REST API, there is likely no need to implement login and logout. In terms of authentication, generally the easiest thing to do is to use HTTP Basic. Spring Security supports Basic out of the box, so that shouldn't be a problem for you.

Here's a good read from Erwin Vervaet's blog about setting up Grails to use HTTP Basic authentication .

Please see How does Spring Security sessions work? to make sense spring security sessions. Your mobile app doesn't provide cookies as browsers on desktop do for you. So you could consider including jsessionid in each mobile request after first login, this is to leverage full authorization and authentication support in spring security than basic auth could do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM