// GetAuthenticatedUser will upgrade the oauth_token to an access token, and
// invoke the appropriate Twitter REST API call to get the User's information.
977003
func (self *TwitterProvider) GetAuthenticatedUser(w http.ResponseWriter, r *http.Request) (User, Token, error) {

	// upgrade the oauth_token to an access token
	token, err := self.OAuth1Mixin.AuthorizeToken(w, r)
	if err != nil {
		return nil, nil, err
	}

	// get the Bitbucket User details
	user := TwitterUser{}
	if err := self.OAuth1Mixin.GetAuthenticatedUser("https://api.twitter.com/1.1/account/settings.json", token, &user); err != nil {
		return nil, nil, err
	}
	return &user, token, err
}
1044023
func (self *OpenIdProvider) GetAuthenticatedUser(w http.ResponseWriter, r *http.Request) (User, Token, error) {

	// Parse the url parameters
	params := r.URL.Query()

	// Check to see if the user successfully authenticated
	if params.Get("openid.mode") == "cancel" {
		return nil, nil, ErrAuthDeclined
	}

	// Get the user details from the URL parameters
	lastName := params.Get("openid.ext1.value.lastname")
	firstName := params.Get("openid.ext1.value.firstname")
	fullName := fmt.Sprintf("%s %s", firstName, lastName)
	email := params.Get("openid.ext1.value.email")

	// Return the User data
	// TODO for now we are re-using the Google User
	user := user{id: email, email: email, name: fullName, provider: self.endpoint }
	return &user, nil, nil
}
710500
func (c *Client) GetUser(userID string) (*User, error) {
	uri := fmt.Sprintf("/1/users/%s", userID)
	resp, err := c.doSimple("GET", uri)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()
	body, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}
	c.trace("GetUser", uri, string(body))
	var user *User
	// TODO(tmc): warn if not == .Zero() before populating?
	return user, json.Unmarshal(body, &user)
}
101381
func (m *GoogleOAuth2Method) GetUserCredentials(c context.Context, r *http.Request) (*oauth2.Token, error) {
	accessToken, err := accessTokenFromHeader(r.Header.Get("Authorization"))
	if err != nil {
		return nil, err
	}
	return &oauth2.Token{
		AccessToken: accessToken,
		TokenType:   "Bearer",
	}, nil
}
843175
func GetAuthentication(o dhcp6.Options) (*Authentication, error) {
	v, err := o.GetOne(dhcp6.OptionAuth)
	if err != nil {
		return nil, err
	}

	a := new(Authentication)
	err = a.UnmarshalBinary(v)
	return a, err
}
246189
func (l *Client) GetAuth(id string) (Auth, error) {
	res := ApiResp{}
	data := Auth{}

	// make the request
	err := l.Get(parseLyticsURL(authEndpoint, map[string]string{"id": id}), nil, nil, &res, &data)
	if err != nil {
		return data, err
	}

	return data, nil
}
1100935
func (c *UserConfig) GetAuthorizeURL(service *Service) (string, error) {
	if c.RequestTokenKey == "" || c.RequestTokenSecret == "" {
		return "", fmt.Errorf("No configured request token")
	}
	token := url.QueryEscape(c.RequestTokenKey)
	return service.AuthorizeURL + "?oauth_token=" + token, nil
}
1149050
func (m *GoogleOAuth2Method) authenticateAgainstGoogle(c context.Context, cfg *Config, accessToken string) (
	*User, time.Duration, error) {

	// Use the anonymous transport client for OAuth2 verification.
	client := cfg.anonymousClient(c)

	// Fetch an info dict associated with the token.
	logging.Infof(c, "oauth: Querying tokeninfo endpoint")
	tokenInfo, err := googleoauth.GetTokenInfo(c, googleoauth.TokenInfoParams{
		AccessToken: accessToken,
		Client:      client,
		Endpoint:    m.tokenInfoEndpoint,
	})
	if err != nil {
		if err == googleoauth.ErrBadToken {
			return nil, 0, err
		}
		return nil, 0, errors.Annotate(err, "oauth: transient error when validating token").
			Tag(transient.Tag).Err()
	}

	// Verify the token contains a validated email.
	switch {
	case tokenInfo.Email == "":
		return nil, 0, fmt.Errorf("oauth: token is not associated with an email")
	case !tokenInfo.EmailVerified:
		return nil, 0, fmt.Errorf("oauth: email %s is not verified", tokenInfo.Email)
	}
	if tokenInfo.ExpiresIn <= 0 {
		return nil, 0, fmt.Errorf("oauth: 'expires_in' field is not a positive integer")
	}

	// Verify `scopes` is subset of tokenInfo.Scope.
	tokenScopes := map[string]bool{}
	for _, s := range strings.Split(tokenInfo.Scope, " ") {
		tokenScopes[s] = true
	}
	for _, s := range m.Scopes {
		if !tokenScopes[s] {
			return nil, 0, fmt.Errorf("oauth: token doesn't have scope %q", s)
		}
	}

	// Good enough.
	id, err := identity.MakeIdentity("user:" + tokenInfo.Email)
	if err != nil {
		return nil, 0, err
	}

	exp := time.Duration(tokenInfo.ExpiresIn) * time.Second
	u := &User{
		Identity: id,
		Email:    tokenInfo.Email,
		ClientID: tokenInfo.Aud,
	}

	return u, exp, nil
}
1163075
func (p *Provider) SessionAuthenticated() bool {
	p.sessionLock.RLock()
	defer p.sessionLock.RUnlock()
	return p.sessionAuth
}
792329
func (p *provider) GetUserIdentity(data *osincli.AccessData) (authapi.UserIdentityInfo, bool, error) {
	userdata := githubUser{}
	if _, err := p.getJSON(p.githubUserApiURL, data.AccessToken, &userdata); err != nil {
		return nil, false, err
	}
	if userdata.ID == 0 {
		return nil, false, errors.New("Could not retrieve GitHub id")
	}

	if len(p.allowedOrganizations) > 0 {
		userOrgs, err := p.getUserOrgs(data.AccessToken)
		if err != nil {
			return nil, false, err
		}

		if !userOrgs.HasAny(p.allowedOrganizations.List()...) {
			return nil, false, fmt.Errorf("User %s is not a member of any allowed organizations %v (user is a member of %v)", userdata.Login, p.allowedOrganizations.List(), userOrgs.List())
		}
		klog.V(4).Infof("User %s is a member of organizations %v)", userdata.Login, userOrgs.List())
	}
	if len(p.allowedTeams) > 0 {
		userTeams, err := p.getUserTeams(data.AccessToken)
		if err != nil {
			return nil, false, err
		}

		if !userTeams.HasAny(p.allowedTeams.List()...) {
			return nil, false, fmt.Errorf("User %s is not a member of any allowed teams %v (user is a member of %v)", userdata.Login, p.allowedTeams.List(), userTeams.List())
		}
		klog.V(4).Infof("User %s is a member of teams %v)", userdata.Login, userTeams.List())
	}

	// The returned email is empty if the user has not specified a public email address in their profile
	if len(userdata.Email) == 0 {
		email, err := p.getUserEmail(data.AccessToken)
		if err == nil {
			userdata.Email = email
		} else {
			klog.V(4).Infof("Failed to get user email information %#v", err)
		}
	}

	identity := authapi.NewDefaultUserIdentityInfo(p.providerName, fmt.Sprintf("%d", userdata.ID))
	if len(userdata.Name) > 0 {
		identity.Extra[authapi.IdentityDisplayNameKey] = userdata.Name
	}
	if len(userdata.Login) > 0 {
		identity.Extra[authapi.IdentityPreferredUsernameKey] = userdata.Login
	}
	if len(userdata.Email) > 0 {
		identity.Extra[authapi.IdentityEmailKey] = userdata.Email
	}
	klog.V(4).Infof("Got identity=%#v", identity)

	return identity, true, nil
}
507123
func (apiutil *ClientUtil) GetUserinfo() (*AhaUserinfo, error) {
	resp, err := apiutil.Client.Get(APIMeURL)
	if err != nil {
		return nil, err
	} else if resp.StatusCode >= 300 {
		return nil, fmt.Errorf("Aha.io API returned Status Code %v", resp.StatusCode)
	}

	bodyBytes, err := hum.ResponseBody(resp)
	if err != nil {
		return nil, err
	}

	userinfo := AhaUserinfoWrap{}
	err = json.Unmarshal(bodyBytes, &userinfo)
	if err == nil {
		apiutil.User = userinfo.User
	}
	return userinfo.User, err
}
333706
func (s *SSO) GetUser(r *http.Request) (u crowd.User, err error) {
	currentCookie, err := r.Cookie(s.CookieConfig.Name)
	if err == http.ErrNoCookie {
		return u, errors.New("no session cookie")
	}

	userSession, err := s.CrowdApp.GetSession(currentCookie.Value)
	if err != nil {
		return u, errors.New("session not valid")
	}

	return userSession.User, nil
}
860145
func (r Network_Firewall_Update_Request) GetAuthorizingUser() (resp datatypes.User_Interface, err error) {
	err = r.Session.DoRequest("SoftLayer_Network_Firewall_Update_Request", "getAuthorizingUser", nil, &r.Options, &resp)
	return
}
47936
func (provider *GitlabProvider) GetUser(creds *common.Credentials) (common.User, error) {

	profileData, err := provider.Get(creds, gitlabEndpointProfile)

	if err != nil {
		return nil, err
	}

	// build user
	user := NewUser(profileData, creds, provider)

	return user, nil
}
605891
func (r *AdminService) GetUser(userName string) *AdminGetUserCall {
	c := &AdminGetUserCall{s: r.s, urlParams_: make(gensupport.URLParams)}
	c.userName = userName
	return c
}
136649
func (obj *Global) GetAuthenticatedUser(ctx context.Context) (string, error) {
	result := &struct {
		Return string	`json:"qReturn"`
	} {}
	err := obj.rpc(ctx, "GetAuthenticatedUser", result)
	return result.Return, err 
}
753904
func (service *Service) GetOauthUser(r *http.Request, w http.ResponseWriter) (username string, err error) {
	oauthSession, err := service.GetSession(r, SessionOauth, "oauthsession")
	if err != nil {
		log.Error(err)
		return
	}
	err = oauthSession.Save(r, w)
	if err != nil {
		log.Error(err)
		return
	}
	savedusername := oauthSession.Values["username"]
	if savedusername != nil {
		username, _ = savedusername.(string)
	}
	return
}