Rest token authentication with HTTP header

前端 未结 2 730
终归单人心
终归单人心 2021-01-06 16:58

This is an existing system with a login screen, now I expose some services as REST service. I build an authentication-token login system for this Rest(jersey) service. User

相关标签:
2条回答
  • 2021-01-06 17:03

    1/2- I'd suggest POSTing the username/password to the server, which can then return the token in the body. Makes most sense to me: you're not actually storing much on the server, so PUT would be wrong, and a query parameter doesn't make sense at all. Headers are supposed to be somewhat consistent across requests, so they don't make sense either. When actually communicating using the token, feel free to use a query parameter or header. Doesn't really matter.

    3- I'd pick a slightly longer hashing algorithm (sha256?)

    0 讨论(0)
  • 2021-01-06 17:13
    1. I would typically pass the token in an HTTP header.

    2. Whether you use POST or PUT shouldn't matter.

    3. Something else I would suggest to help prevent replay type attacks would be to include a nonce (ever increasing value) with each POST request. The server would then track the last used nonce and prevent any requests that use a previously used nonce from executing.

    0 讨论(0)
提交回复
热议问题