rest - Java POST request to get token from web service -


i need access java application restful web service uses token-based authentication. understood best choice purpose use jax-rs-based libraries jersey, new matter. maybe me giving example code of proper request token web service.

what have:

  • uri of token issuing server. uses oauth2 authorization.
  • clientid , clientsecret. have submit them token issuing server verify them , return token.
  • uri of web service itself.
  • username , password service access.

as understood, token have send post request along following headers:

  • "authorization", "basic ywrhmgi3nticdscsn2i0mjnjm2ewnwq0mjm2ztg6qu1hs0ltuezjaufsr3dgmmj3njzzvi9ec05yztd0zkeerfrvegeznond0=" ("basic " + base64 encoded "clientid:clientsecret")
  • "accept", "application/x-www-form-urlencoded"
  • "content-type", "application/json;odata=verbose"

and following parameter:

grant_type=password&username=someusername&password=somepassword&scope=profile

hope me example code.

some points:

  • url request specify 1 belonging resource owner password credentials grant. sure under scenario grant meant (more details here).
  • jax-rs implementing rest apis, not client-side calls (maybe talking "jax-rs client"? if that's case, in terms of oauth, falls last point category other http client).
  • there libraries can handle obtaining access token you, need provide properties , decide resulting token. example, if ok using spring, spring security oauth2 (talking "client role" configuration only; using external authorization server).
  • if libraries not fit case: need implement/use http client standard calls authorization server (they rest apis). options: apache httpcomponents, spring resttemplate, jdk httpurlconnection

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -