c# - What should I fetch from gmail DotNetOpenAuth? -
i want use dotnetopenauth in website authentication + authorization (gmail).
however, ask: should persist?
i thought:
- in db: each user save guid , gmail (fetched)
- in formauthentication cookie guid have assigned user.
any other suggestions?
public bool login() { iauthenticationresponse authresponse = googleconsumerhandler.relyingparty.getresponse(); if (authresponse != null) { handleauthresponse(authresponse); } else { handleauthnullresponse(authresponse); } return false; } #region private methods private void handleauthresponse(iauthenticationresponse authresponse) { switch (authresponse.status) { case authenticationstatus.authenticated: state.fetchresponse = authresponse.getextension<fetchresponse>(); var consumer = new webconsumer(googleconsumerhandler.servicedescription, mconsumertokenmanager); authorizedtokenresponse accesstoken = consumer.processuserauthorization(authresponse); if (accesstoken != null) { var email = authresponse.claimedidentifier; //existing or new guid userid = mcrmservice.getuserid(email, accesstoken.accesstoken); state.googleaccesstoken = accesstoken.accesstoken; formsauthentication.setauthcookie(userid.tostring(), false); //authenticat , authorized //response.redirect("~/browser.htm"); } else { //authenticated , not authorized //multiview1.setactiveview(authorizationdenied); } break; case authenticationstatus.canceled: break; case authenticationstatus.failed: break; default: //not authenticated //this.multiview1.setactiveview(this.authenticationfailed); break; } } private void handleauthnullresponse(iauthenticationresponse authresponse) { // google requires realm , consumer key equal, // constrain realm match realm in web.config file. // mean return_to url must fall under key, // means sample work on public web site // registered google. // customize realm use http or https based on // return_to url (which page). var consumer = new webconsumer(googleconsumerhandler.servicedescription, mconsumertokenmanager); //realm realm = "http://localhost:8976/"; realm realm = system.web.httpcontext.current.request.url.scheme + uri.schemedelimiter + consumer.consumerkey + "/"; iauthenticationrequest authreq = googleconsumerhandler.relyingparty.createrequest(googleconsumerhandler.googleopidentifier, realm); // prepare oauth extension string scope = googleconsumerhandler.getscopeuri(googleconsumerhandler.applications.gmail); consumer.attachauthorizationrequest(authreq, scope); // want user's email address var fetch = new fetchrequest(); fetch.attributes.addrequired(wellknownattributes.contact.email); authreq.addextension(fetch); authreq.redirecttoprovider(); }
for authentication purposes should store openid claimedidentifier in iauthenticationresponse
object. serves "primary key" users can recognize them when return. suggest use claimed_id formsauthentication username instead of random guid well. storing email address collect fine, it's inadvisable use means recognize returning user.
remember can't log in "gmail users". can log in openid users, may use provider. can limit "google" users filtering on iauthenticationresponse.provider.uri
google op endpoint, you're not guaranteed accounts use gmail (their email address might foo@bar.com anyway).
finally, if need authentication , email address (whatever email is) can using openid ax extension (built dnoa) , don't need "authorization", might simplify code.
Comments
Post a Comment