OAuth2.0 UserInfo reference implementation to get logged in user information using the access token
@param req   The Http Request with authorization header
@return      User Information Json Object
492989
@GET
    @Produces(MediaType.APPLICATION_JSON)
    @Path("/userinfo")
    @Description("Returns the user info of the user who is logged in.")
    public PrincipalUserDto userInfo(@Context HttpServletRequest req) {
        String userName=findUserByToken(req);
        PrincipalUser user = _uService.findUserByUsername(userName);
        return PrincipalUserDto.transformToDto(user);
    }
558302
public static String getHeaders(final HttpServletRequest req) {
    Enumeration en = req.getHeaderNames();
    StringBuffer sb = new StringBuffer();

    while (en.hasMoreElements()) {
      String name = (String) en.nextElement();
      sb.append(name);
      sb.append(": ");
      sb.append(req.getHeader(name));
      sb.append("\n");
    }
    return sb.toString();
  }
381400
def server_info(self, verbose=False):
        '''
        
        '''
        url = '{}/{}'.format(self.rest_url, 'serverinfo')
        return self.__auth_req_get(url, verbose=verbose)
903175
public GetUserInfoResponse getUserInfo(String openid) {
        BeanUtil.requireNonNull(openid, "openid is null");
        GetUserInfoResponse response;
        LOG.debug("获取关注者信息.....");
        String url = BASE_API_URL + "cgi-bin/user/info?access_token=#&lang=zh_CN&openid=" + openid;
        BaseResponse r = executeGet(url);
        String resultJson = isSuccess(r.getErrcode()) ? r.getErrmsg() : r.toJsonString();
        response = JSONUtil.toBean(resultJson, GetUserInfoResponse.class);
        return response;
    }
692784
public OAuthAccessToken refreshToken(RequestContext requestContext, OAuthAccessToken token) {
    OAuthAccessToken result = token;
    
    String[] scopes = token.getScopes();
    String tokenUrl = String.format("%s/realms/%s/protocol/openid-connect/token", getServerUrl(), getRealm());
    
    HttpPost httpPost = new HttpPost(tokenUrl);
    
    try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
      List<NameValuePair> params = new ArrayList<NameValuePair>();
      params.add(new BasicNameValuePair("client_id", getApiKey()));
      params.add(new BasicNameValuePair("client_secret", getApiSecret()));
      params.add(new BasicNameValuePair("grant_type", "refresh_token"));
      params.add(new BasicNameValuePair("refresh_token", token.getRefreshToken()));

      httpPost.setEntity(new UrlEncodedFormEntity(params));
      try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
        StatusLine statusLine = response.getStatusLine();
        
        if (statusLine.getStatusCode() == 200) {
          HttpEntity entity = response.getEntity();
          
          ObjectMapper objectMapper = new ObjectMapper();
          try (InputStream stream = entity.getContent()) {
            RefreshTokenResponse refreshTokenResponse = objectMapper.readValue(stream, RefreshTokenResponse.class);
            Date expiresAt = getExpiresAt(refreshTokenResponse.getExpiresIn());
            result = new OAuthAccessToken(token.getExternalId(), refreshTokenResponse.getAccessToken(), refreshTokenResponse.getRefreshToken(), expiresAt, scopes);
            AuthUtils.purgeOAuthAccessTokens(requestContext, getName());
            AuthUtils.storeOAuthAccessToken(requestContext, getName(), result);            
          }
          
          EntityUtils.consume(entity);
        } else {
          logger.log(Level.WARNING, String.format("Failed to refresh access token with message [%d]: %s", statusLine.getStatusCode(), statusLine.getReasonPhrase()));
        }
      }
    } catch (IOException e) {
      logger.log(Level.WARNING, "Failed to refresh access token", e);
    }
    
    return result;
  }
117842
def getUserInfo(self):
        
        userJson = self.httpGet(ReaderUrl.USER_INFO_URL)
        result = json.loads(userJson, strict=False)
        self.userId = result['userId']
        return result
134735
public function userinfo($access_token)
    {
        return $this->apiClient->get()
        ->userinfo()
        ->withHeader(new ContentType('application/json'))
        ->withHeader(new AuthorizationBearer($access_token))
        ->call();
    }
691454
def get_login_info(self, auth_code, provider_access_token=None):
        
        return self._post(
            'service/get_login_info',
            params={
                'provider_access_token': provider_access_token,
            },
            data={
                'auth_code': auth_code,
            }
        )
370436
@RequestMapping(
            value = USERINFO_ENDPOINT_URI,
            produces = USERINFO_CONTENT_TYPE,
            method = {RequestMethod.GET, RequestMethod.POST})
    public String userInfo(
            HttpServletRequest request,
            @RequestParam(value = "claims", required = false) String claims,
            @RequestParam(value = "groups", required = false) String groups) {

        final IPerson person = personManager.getPerson(request);
        return createToken(person, claims, groups);
    }
115620
@Override
    public String getAuthorizationHeader(HttpRequest req) {
        return generateAuthorizationHeader(req.getMethod().name(), req.getURL(), req.getParameters(), oauthToken);
    }
376097
public GetOauthUserInfoResponse getOauthUserInfo(String code){
        if(StrUtil.isBlank(code)){
            throw new NullPointerException("code is null");
        }
        GetOauthUserInfoResponse response;
        String url = BASE_API_URL + "cgi-bin/user/getuserinfo?access_token=#&code=" + code;
        BaseResponse r = executeGet(url);
        String jsonResult = isSuccess(r.getErrcode()) ? r.getErrmsg() : r.toJsonString();
        response = JSONUtil.toBean(jsonResult, GetOauthUserInfoResponse.class);
        return response;
    }
748592
public static Single<String> getUserInfo(String apikey) {
        Map<String, String> params = new HashMap<>();
        params.put("apikey", apikey);
        return post(URI_GET_USER_INFO, params);
    }
708316
protected Credential getCredential(HttpServletRequest req) {
    Credential cred = (Credential) req.getAttribute(AUTH_CREDENTIAL);
    return cred;
  }
24637
def get_user_info(self):
        
        response = self._session.get(BASE_URL_TSQUARE + '/user/current.json')
        response.raise_for_status() # raises an exception if not 200: OK
        user_data = response.json()
        del user_data['password'] # tsquare doesn't store passwords
        return TSquareUser(**user_data)
991059
def getAuthenticatedUser(self, headers=None, query_params=None, content_type="application/json"):
        
        uri = self.client.base_url + "/self"
        return self.client.get(uri, None, headers, query_params, content_type)
349736
protected String getStoredToken(HttpServletRequest req) {
		HttpSession session = req.getSession(false);
		
		if (session == null)
			return null;
		
		return (String) session.getAttribute(ATR_SESSION_TOKEN);
	}
528392
public static UserGetShakeInfoResult userGetShakeInfo(String accessToken,
                                                          UserGetShakeInfo userGetShakeInfo) {
        return userGetShakeInfo(accessToken,
                JsonUtil.toJSONString(userGetShakeInfo));
    }