angularjsspring-securitysession-cookiesjhipstercsrf-protection

Jhipster login / authentication in mobile app


How to get a session cookie and the CSRF token from jhipster then use them in your calls to the API from mobile app. I am using HTTP session authentication.

JHipster configuration, a .yo-rc.json file generated in the root folder

{
"generator-jhipster": {
"jhipsterVersion": "3.0.0",
"baseName": "vconnect",
"packageName": "com.zenfact.vconnect",
"packageFolder": "com/zenfact/vconnect",
"serverPort": "8080",
"authenticationType": "session",
"hibernateCache": "ehcache",
"clusteredHttpSession": "no",
"websocket": "no",
"databaseType": "sql",
"devDatabaseType": "postgresql",
"prodDatabaseType": "postgresql",
"searchEngine": "elasticsearch",
"buildTool": "maven",
"enableSocialSignIn": false,
"rememberMeKey": "559bbe3167552d040ba24d16506d389a7ba851c3",
"useSass": false,
"applicationType": "monolith",
"testFrameworks": [
"gatling"
],
"enableTranslation": true,
"nativeLanguage": "en",
"languages": [
"en",
"zh-cn",
"fr",
"hi",
"ja"
]
}
}

Solution

  • I don't have any mobile experience but cookies are known to be difficult with mobile. I'd recommend using jhipster's Oauth2 option instead. Then you just need to get an access token and add the header "Authorization: Bearer " to your api calls.