java - issue with OAuth2 oltu -
i working on securing our rest api's oauth2. code have written not complete code, testing it..
using below code making token request.
public class oauthclientmine { public static void main (string args[]) throws oauthsystemexception, ioexception, oauthproblemexception{ gettoken(); } public static void gettoken() throws oauthsystemexception, ioexception, oauthproblemexception{ oauthclientrequest request = oauthclientrequest .tokenlocation("http://localhost:8080/xina/webapi/token") .setgranttype(granttype.authorization_code) .setclientid("xina_client") .setclientsecret("xinaisawesome") .setcode("xyxyxy") .setusername("john") .setredirecturi("http://localhost:8080/xina/webapi/token") .setpassword("password") .buildquerymessage(); oauthclient oauthclient = new oauthclient(new urlconnectionclient()); oauthaccesstokenresponse oauthresponse = oauthclient.accesstoken(request); final oauthaccesstokenresponse oauthresponse = oauthclient.accesstoken(request); system.out.println(oauthresponse.getaccesstoken()); system.out.println(oauthresponse.getexpiresin()); system.out.println( request.getlocationuri()); }} once token request received validating client details , send authorized token using below code.
@path("/token") public class authorizeclient { @post @consumes("application/x-www-form-urlencoded") @produces("application/json") public response gettoken(@context httpservletrequest tokenrequest) throws oauthsystemexception, oauthproblemexception{ //oauthtokenrequest oauthrequest = new oauthtokenrequest(tokenrequest); system.out.println( request.getclass()); oauthissuer oauthissuerimpl = new oauthissuerimpl(new md5generator()); oauthresponse response = oauthasresponse .tokenresponse(httpservletresponse.sc_ok) .setaccesstoken(oauthissuerimpl.accesstoken()) .setexpiresin("3600") .buildjsonmessage(); return response.status(response.getresponsestatus()) .entity(response.getbody()) .build(); }} but issue facing request tokenrequest null, not sure how can intercept client details before sending token
Comments
Post a Comment