Incremental Google OAuth with Asp.Net Owin Oauth -


i'm looking solution doing incremental authorization against google's api's asp.net's owin oauth libraries.

i know how set scope specific api's, incrementally , can see how set on globally.

doc on google oauth incremental auth... https://developers.google.com/accounts/docs/oauth2webserver#incrementalauth

current vb code...

public sub configureauth(app iappbuilder)      dim googlecreds = new googleoauth2authenticationoptions() {                 .clientid = "xxxx",                 .clientsecret = "xxx"     }      googlecreds.scope.add("https://www.googleapis.com/auth/analytics.readonly")     app.usegoogleauthentication(googlecreds)      ' add way specify googledrive, youtube, google+ scopes     ' example code doesn't work add 2nd google oauth listener     googlecreds.scope.clear()     googlecreds.scope.add("https://www.googleapis.com/auth/drive.file")     googlecreds.authenticationtype = "googledrive"     app.usegoogleauthentication(googlecreds)  end class 

here solution came with. involves passing "scope" parameter in url , parsing in "onapplyredirect" function of authentication options , manually injecting correct scope url redirect url.

    dim googlecreds = new googleoauth2authenticationoptions() {         .clientid = "xxx",         .clientsecret = "xxx",         .provider = new microsoft.owin.security.google.googleoauth2authenticationprovider() { _             .onapplyredirect = function(context)                                    dim querystring = httpcontext.current.request.querystring.tostring()                                    dim queryparms = httputility.parsequerystring(querystring)                                     ' change value of "redirect" here                                    ' e.g. append access_type=offline                                    dim redirect string = context.redirecturi                                    redirect += "&access_type=offline"                                    redirect += "&approval_prompt=force"                                    redirect += "&include_granted_scopes=true"                                     dim uri = new uri(redirect)                                     if (not string.isnullorempty(queryparms.get("scope")))                                        dim scope = queryparms.get("scope")                                        dim redirectquerystring = httputility.parsequerystring(uri.query)                                        select case scope                                            case "analytics"                                                redirectquerystring.set("scope", "https://www.googleapis.com/auth/analytics.readonly")                                            case "youttube"                                                redirectquerystring.set("scope", "https://gdata.youtube.com")                                            case "drive"                                                redirectquerystring.set("scope", "https://www.googleapis.com/auth/drive.file")                                            case else                                                loggingutility.logerrormessage("invalid scope passed in: scope: " + scope)                                        end select                                        redirect = uri.getleftpart(uripartial.path) + "?" + redirectquerystring.tostring()                                    end if                                     context.response.redirect(redirect)                                 end function, _         }     }      'google analytics     app.usegoogleauthentication(googlecreds) 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -