I am able to login(/api/login) and have been able to successfully make a GET request. However, I cannot seem to figure out how to make a POST request, and likewise I have not been able to logout (/api/logout).
Controller: (com.example.test)
static allowedMethods = [secret:['POST', 'GET']]
@Secured(['ROLE_ADMIN'])
def secret() {
render "You have ACCESS!!!"
}
Curl to login (and HTTP response):
curl -v -H "Content-Type: application/json" -X POST -d
'{"username":"user", "password":"pass"}'
http://localhost:8080/restplug/api/login
< HTTP/1.1 200 OK
{"username":"user","roles":"ROLE_ADMIN"],
"access_token":"a2d4biqg7oqu0ig4m22pj20qsesva81d",
"token_type":"Bearer"}
Curl for GET request (example for method secret):
curl -v -i -H "Authorization: Bearer a2d4biqg7oqu0ig4m22pj20qsesva81d"
-X GET http://localhost:8080/restplug/TestData/secret
My POST requests always results in being redirected to Login Page (even when I pass the token).
Kindly show examples of how to do a post request using curl, or something like a rest client (Postman). Also if possible, show how to logout (/api/logout)
Configuration
grails.plugin.springsecurity.rest.login.active=true
grails.plugin.springsecurity.rest.login.endpointUrl='/api/login'
grails.plugin.springsecurity.rest.login.failureStatusCode=401
grails.plugin.springsecurity.rest.login.useJsonCredentials=true
grails.plugin.springsecurity.rest.login.usernamePropertyName='username'
grails.plugin.springsecurity.rest.login.passwordPropertyName='password'
grails.plugin.springsecurity.rest.logout.endpointUrl='/api/logout'
grails.plugin.springsecurity.rest.token.storage.useGorm = true
grails.plugin.springsecurity.rest.token.storage.gorm.tokenDomainClassName="com.example.AuthenticationToken"
grails.plugin.springsecurity.rest.token.storage.gorm.tokenValuePropertyName="tokenValue"
grails.plugin.springsecurity.rest.token.storage.gorm.usernamePropertyName='username'
grails.plugin.springsecurity.rest.login.usernamePropertyName='username'
grails.plugin.springsecurity.rest.login.passwordPropertyName='password'
grails.plugin.springsecurity.rest.token.generation.useSecureRandom = true
Attempts using POST that failed
Here are some of the what I tried using Curl and postman:
curl -v -X POST --form "access_token=bdv3de54oglo2i997k1tomvdgptm2ojq"
http://localhost:8080/restplug/TestData/secret
curl -v -X POST -H "Content-Type: application/x-www-form-urlencode"
--form "access_token=bdv3de54oglo2i997k1tomvdgptm2ojq"
http://localhost:8080/restplug/TestData/secret
And also using postman (attached image):