// UseGenericOAuth2 validates the CLI parameters to enable generic oauth support
975428
func (s *Server) UseGenericOAuth2() bool {
	return s.TokenSecret != "" && s.GenericClientID != "" &&
		s.GenericClientSecret != "" && s.GenericAuthURL != "" &&
		s.GenericTokenURL != ""
}
1252379
func (cli *OpsGenieClient) UserV2() (*OpsGenieUserV2Client, error) {
	cli.makeHTTPTransportSettings()

	userClient := new(OpsGenieUserV2Client)
	userClient.SetOpsGenieClient(*cli)

	if cli.opsGenieAPIURL == "" {
		userClient.SetOpsGenieAPIUrl(endpointURL)
	}

	return userClient, nil
}
679587
func checkCredentialsForGoogleAuth(s *service, _ string, accessToken string) (rest.ResponseDTOUserInfo, *servicehelper.Error) {
	conf := &oauth2.Config{
		ClientID:     os.Getenv("GOOGLE_LOGIN_API_CLIENT_ID"),
		ClientSecret: os.Getenv("GOOGLE_LOGIN_API_SECRET_ID"),
		Scopes: []string{
			"https://www.googleapis.com/auth/userinfo.email",
		},
		Endpoint: google.Endpoint,
	}

	tok := oauth2.Token{
		AccessToken: accessToken,
	}

	client := conf.Client(context.Background(), &tok)
	email, err := client.Get("https://www.googleapis.com/oauth2/v3/userinfo")
	if err != nil {
		return rest.ResponseDTOUserInfo{}, &servicehelper.Error{
			Detail: errors.New("error while trying to check credentials"),
		}
	}
	defer email.Body.Close()
	data, _ := ioutil.ReadAll(email.Body)

	var dat map[string]interface{}
	if err := json.Unmarshal(data, &dat); err != nil {
		return rest.ResponseDTOUserInfo{}, &servicehelper.Error{
			Detail: errors.New("error while trying to check credentials"),
		}
	}
	user, err := s.repo.FindByEmail(dat["email"].(string))
	if err != nil {
		return rest.ResponseDTOUserInfo{}, &servicehelper.Error{
			Detail: errors.New("incorrect username or password"),
		}
	}
	return rest.ResponseDTOUserInfo{
		UserId: user.ID,
		Email:  user.Email,
	}, nil
}
29095
func AsDefaultCredentials(ctx *AssertContext) {
	conf := ctx.Config
	Expect(conf).ToNot(BeNil(),
		"cannot set static AssertContext without config")

	tempFile, err := ioutil.TempFile("", "bosh-gcscli-service-account-file")
	Expect(err).ToNot(HaveOccurred())
	defer tempFile.Close()

	tempFile.WriteString(ctx.serviceAccountFile)

	ctx.serviceAccountPath = tempFile.Name()
	os.Setenv(GoogleAppCredentialsEnv, ctx.serviceAccountPath)

	conf.CredentialsSource = config.DefaultCredentialsSource
}
1083399
func preSignatureV2(cred auth.Credentials, method string, encodedResource string, encodedQuery string, headers http.Header, expires string) string {
	stringToSign := getStringToSignV2(method, encodedResource, encodedQuery, headers, expires)
	return calculateSignatureV2(stringToSign, cred.SecretKey)
}
448494
func (p *Prometheus) UseWithAuth(e *gin.Engine, accounts gin.Accounts) {
	e.Use(p.HandlerFunc())
	p.SetMetricsPathWithAuth(e, accounts)
}
836166
func UseACLs(c context.Context, acls *gitacls.ACLs) context.Context {
	return Use(c, &implementation{acls: acls})
}
1364566
func (c *Ctx) UseCertificate(cert *Certificate) error {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()
	c.cert = cert
	if int(C.SSL_CTX_use_certificate(c.ctx, cert.x)) != 1 {
		return errorFromErrorQueue()
	}
	return nil
}
1030053
func NewOAuth2Tripper(creds *common.Credentials, provider common.Provider) *OAuth2Tripper {
	return &OAuth2Tripper{common.GetRoundTripper(), creds, provider}
}
1167174
func OAuth2AuthorizeExplicitFactory(config *Config, storage interface{}, strategy interface{}) interface{} {
	return &oauth2.AuthorizeExplicitGrantHandler{
		AccessTokenStrategy:      strategy.(oauth2.AccessTokenStrategy),
		RefreshTokenStrategy:     strategy.(oauth2.RefreshTokenStrategy),
		AuthorizeCodeStrategy:    strategy.(oauth2.AuthorizeCodeStrategy),
		CoreStorage:              storage.(oauth2.CoreStorage),
		AuthCodeLifespan:         config.GetAuthorizeCodeLifespan(),
		RefreshTokenLifespan:     config.GetRefreshTokenLifespan(),
		AccessTokenLifespan:      config.GetAccessTokenLifespan(),
		ScopeStrategy:            config.GetScopeStrategy(),
		AudienceMatchingStrategy: config.GetAudienceStrategy(),
		TokenRevocationStorage:   storage.(oauth2.TokenRevocationStorage),
		IsRedirectURISecure:      config.GetRedirectSecureChecker(),
	}
}
963291
func NewOAuth2Provider(conf *oauth2.Config) macaron.Handler {

	return func(s session.Store, c *macaron.Context, w http.ResponseWriter, r *http.Request) {
		if r.Method == "GET" {
			switch r.URL.Path {
			case PathLogin:
				login(conf, s, w, r)
			case PathLogout:
				logout(s, w, r)
			case PathCallback:
				handleOAuth2Callback(conf, s, w, r)
			}
		}
		tk := unmarshallToken(s)
		if tk != nil {
			// check if the access token is expired
			if tk.Expired() && tk.Refresh() == "" {
				s.Delete(keyToken)
				tk = nil
			}
		}
		// Inject tokens.
		c.MapTo(tk, (*Tokens)(nil))
	}
}
646261
func UseOrCreateObject(t Typer, c ObjectCreater, gvk unversioned.GroupVersionKind, obj Object) (Object, error) {
	if obj != nil {
		into, _, err := t.ObjectKind(obj)
		if err != nil {
			return nil, err
		}
		if gvk == *into {
			return obj, nil
		}
	}
	return c.New(gvk)
}
494791
func (_class HostClass) DisableExternalAuth(sessionID SessionRef, host HostRef, config map[string]string) (_err error) {
	_method := "host.disable_external_auth"
	_sessionIDArg, _err := convertSessionRefToXen(fmt.Sprintf("%s(%s)", _method, "session_id"), sessionID)
	if _err != nil {
		return
	}
	_hostArg, _err := convertHostRefToXen(fmt.Sprintf("%s(%s)", _method, "host"), host)
	if _err != nil {
		return
	}
	_configArg, _err := convertStringToStringMapToXen(fmt.Sprintf("%s(%s)", _method, "config"), config)
	if _err != nil {
		return
	}
	_, _err =  _class.client.APICall(_method, _sessionIDArg, _hostArg, _configArg)
	return
}
446457
func NewGenericFlag(fl cli.GenericFlag) *GenericFlag {
	return &GenericFlag{GenericFlag: fl, set: nil}
}
381598
func NewOauth2Scopes(in interface{}, context *compiler.Context) (*Oauth2Scopes, error) {
	errors := make([]error, 0)
	x := &Oauth2Scopes{}
	m, ok := compiler.UnpackMap(in)
	if !ok {
		message := fmt.Sprintf("has unexpected value: %+v (%T)", in, in)
		errors = append(errors, compiler.NewError(context, message))
	} else {
		// repeated NamedString additional_properties = 1;
		// MAP: string
		x.AdditionalProperties = make([]*NamedString, 0)
		for _, item := range m {
			k, ok := compiler.StringValue(item.Key)
			if ok {
				v := item.Value
				pair := &NamedString{}
				pair.Name = k
				pair.Value = v.(string)
				x.AdditionalProperties = append(x.AdditionalProperties, pair)
			}
		}
	}
	return x, compiler.NewErrorGroupOrNil(errors)
}
789151
func auth(ctx *importer.SetupContext) (*oauth2.Config, error) {
	clientID, secret, err := ctx.Credentials()
	if err != nil {
		return nil, err
	}
	return &oauth2.Config{
		ClientID:     clientID,
		ClientSecret: secret,
		Endpoint: oauth2.Endpoint{
			AuthURL:  authURL,
			TokenURL: tokenURL,
		},
		RedirectURL: ctx.CallbackURL(),
		// No scope needed for foursquare as far as I can tell
	}, nil
}
135332
func GetRegistryAuth(ctx context.Context, resolver AuthConfigResolver, imageName string) (*types.AuthConfig, error) {
	distributionRef, err := reference.ParseNormalizedNamed(imageName)
	if err != nil {
		return nil, fmt.Errorf("Failed to parse image name: %s: %s", imageName, err)
	}
	imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, nil, resolver, distributionRef.String())
	if err != nil {
		return nil, fmt.Errorf("Failed to get imgRefAndAuth: %s", err)
	}
	return imgRefAndAuth.AuthConfig(), nil
}