i'm working on application add tasks accounts using "google tasks api" java using oauth 2.0.
the problem every time want add task on account have authentication page , authorize using account , password , , wait callback add task , not practical
i wonder if there way authorize java application without executing , avoid callback function :
maybe sending link owner of gmail account, sending email, etc..
so want :
- i want user of application authorize outside without executing it
- when execute add task want cheek out if authorized user add task , if not skip user etc..
thx
the typical oauth 2.0 flow goes follows:
- send request permission access user's data within scope (https://www.googleapis.com/auth/tasks)
- user gets authentication screen must log in , allow app "manage tasks"
- your app receives authorization code
- your app must exchange authorization code access token , refresh token.
the access token can used make authenticated requests users data, expire after set amount of time. refresh token never expires (unless user revokes app's privileges in account settings) , can used new request token.
you can see whole flow here in oauth2.0 playground.
if follow flow correctly , save 2 tokens (in database or file, depending on platform) user should have see screen only once.
now best part: the google api java client library should handle you. exact class use changes depending on version of library use, should setting place persist tokens when creating service object. example, calendar api:
// example we're saving credentials in file on system, // rather database. filecredentialstore credentialstore = new filecredentialstore( new file(system.getproperty("user.home"), ".credentials/calendar.json"), json_factory); // set authorization code flow googleauthorizationcodeflow flow = new googleauthorizationcodeflow.builder( http_transport, json_factory, clientsecrets, collections.singleton(calendarscopes.calendar)) .setcredentialstore(credentialstore) // store tokens .build(); you can check out in calendar-cmdline-sample here. there plenty of other samples too, see authorization flow on app engine or android.
Comments
Post a Comment