c# - Google API: How can I check if the authentication was done successfully? -
using google.apis.analytics.v3 library in .net, doing oauth2 authentication google analytics api, this:
string[] scopes = new string[] { analyticsservice.scope.analytics, // view , manage analytics data analyticsservice.scope.analyticsedit, // edit management actives analyticsservice.scope.analyticsmanageusers, // manage users analyticsservice.scope.analyticsreadonly}; // view analytics data usercredential credential = googlewebauthorizationbroker.authorizeasync( new clientsecrets { clientid = clientid, clientsecret = clientsecret } , scopes , username , cancellationtoken.none , new databasedatastore("analytics")).result; analyticsservice service = new analyticsservice(new baseclientservice.initializer() { httpclientinitializer = credential, applicationname = "masterpiece" }); the problem @ end, don't know if authentication successful or not, don't see way of getting sort of message implementation. normally, works fine , can go on interrogating api. if revoke token have stored username, implementation not tell me service not authenticated , when try interrogate api afterwards error.
how in world should verify if authentication done before start accessing api methods? if authentication fails, want able remove revoke token data store, , try authentication again, asking user permission.
there few things can go wrong should consider.
- the user click accept. no problem here can check
credential.token.accesstokensee got access token , can access api. - the user not click accept clicks cancle instead. in instance exception throw. why code above should in try catch. [system.aggregateexception] innerexception = {"error:\"access_denied\", description:\"\", uri:\"\""}
- third option user nothing in case code hang waiting result user. (bug report: still working on solution one)
now worry if delete user in databasedatastore happen. should happen same if there new user. if code in databasedatastore correct system detect doesn't have user , prompt user again authentication. client library should you, or rather databasedatastore should. recommend testing around user , filedatastore see how works. if yours not prompting new authentication when delete user system there wrong databasedatastore.
recommendations.
- don't request scopes request need.
- put code in try catch in event don't authentication going throw error need catch it.
- test on accesstoken if worried it.

Comments
Post a Comment