Note that if there is no currently logged-in user, #getUserId(HttpServletRequest) will
throw a NullPointerException. Example to require login for all pages:
any/
Sample usage:
publicclassServletSampleextendsAbstractAppEngineAuthorizationCodeServlet{@OverrideprotectedvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsIOException{// do stuff}@OverrideprotectedStringgetRedirectUri(HttpServletRequestreq)throwsServletException,IOException{GenericUrlurl=newGenericUrl(req.getRequestURL().toString());url.setRawPath("/oauth2callback");returnurl.build();}@OverrideprotectedAuthorizationCodeFlowinitializeFlow()throwsIOException{returnnewAuthorizationCodeFlow.Builder(BearerToken.authorizationHeaderAccessMethod(),newUrlFetchTransport(),newGsonFactory(),newGenericUrl("https://server.example.com/token"),newBasicAuthentication("s6BhdRkqt3","7Fjfp0ZBr1KtDRbnfVdmIw"),"s6BhdRkqt3","https://server.example.com/authorize").setCredentialStore(newAppEngineCredentialStore()).build();}}
Returns the user ID for the given HTTP servlet request. This identifies your application's user
and is used to fetch persisted credentials for that user. Most commonly, this will be a user id
stored in the session or even the session id itself.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-04-17 UTC."],[],[]]