// OAuthProvider details. Useful for services that can be installed on your own side
763819
func (c *Context) OAuthProvider() *OAuthProvider {

	service := c.Service()
	if c.ServiceBaseURL.Host == "" || c.ServiceBaseURL.Host == service.DefaultBaseURL.Host {
		return service.DefaultOAuthProvider()
	} else if c.ServiceBaseURL.Host != "" {

		p, _ := findOauthProviderByHost(c.db, c.ServiceBaseURL.Host)
		if p == nil {
			p = &OAuthProvider{BaseURL: c.ServiceBaseURL, Service: c.ServiceName}
		}
		/*if err != nil {
			c.Log().WithError(err).WithField("host", c.ServiceBaseURL.Host).Error("Can't get OAuthProvider")
		}*/

		return p
	}
	c.Log().Error("Can't get OAuthProvider – empty ServiceBaseURL")

	return nil
}
1252610
func newAuthProvider(c *Context) (dockerauth.AuthProvider, error) {
	provider := dockerauth.NewMultiAuthProvider()
	provider.AddProvider(dockerauth.NewECRAuthProvider(func(region string) dockerauth.ECR {
		return ecr.New(c, &aws.Config{Region: aws.String(region)})
	}))

	if dockerConfigPath := c.String(FlagDockerAuth); dockerConfigPath != "" {
		dockerConfigFile, err := os.Open(dockerConfigPath)
		if err != nil {
			return nil, err
		}

		defer dockerConfigFile.Close()

		dockerConfigProvider, err := dockerauth.NewDockerConfigAuthProvider(dockerConfigFile)
		if err != nil {
			return nil, err
		}

		provider.AddProvider(dockerConfigProvider)
	}

	return provider, nil
}
735946
func (o *OAuthProvider) OAuth1Client(c *Context) *oauth.Consumer {

	if o.ID == "" {
		log.Error(errors.New("Can't get OAuth1Client – ID not set"))
		return nil
	}

	service := c.Service()
	config := service.DefaultOAuth1

	if config.AccessTokenReceiver == nil {
		log.Error(errors.New("Can't get OAuth1Client – AccessTokenReceiver not set"))

		return nil
	}

	config.Key = o.ID
	config.Secret = o.Secret
	config.AccessTokenURL = replaceBaseURL(config.AccessTokenURL, o.BaseURL)
	config.AuthorizeTokenURL = replaceBaseURL(config.AuthorizeTokenURL, o.BaseURL)
	config.RequestTokenURL = replaceBaseURL(config.RequestTokenURL, o.BaseURL)

	consumer := oauth.NewConsumer(
		o.ID,
		o.Secret,
		oauth.ServiceProvider{
			RequestTokenUrl:   config.RequestTokenURL,
			AuthorizeTokenUrl: config.AuthorizeTokenURL,
			AccessTokenUrl:    config.AccessTokenURL,
		},
	)
	consumer.AdditionalAuthorizationUrlParams = service.DefaultOAuth1.AdditionalAuthorizationURLParams
	return consumer
}
1205669
func authProviderFlag(usage string, required bool) cli.Flag {
	return newPlaceholder("auth, a", "AUTHPROVIDER", usage, "", "TORUS_AUTH_PROVIDER", required)
}
1333711
func LoginProviderFrom(ctx context.Context) (name string, ok bool) {
	name, ok = ctx.Value(loginProviderNameKey).(string)
	return
}
1290217
func LazyProvide(creds LazyAuthConfiguration, image string) AuthConfig {
	if creds.Provider != nil {
		entry := *creds.Provider.LazyProvide(image)
		return DockerConfigEntryToLazyAuthConfiguration(entry).AuthConfig
	}
	return creds.AuthConfig
}
118063
func NewOAuth2Provider(config *Config, authUrl, tokenUrl string) negroni.HandlerFunc {
	c := &oauth2.Config{
		ClientID:     config.ClientID,
		ClientSecret: config.ClientSecret,
		Scopes:       config.Scopes,
		RedirectURL:  config.RedirectURL,
		Endpoint: oauth2.Endpoint{
			AuthURL:  authUrl,
			TokenURL: tokenUrl,
		},
	}

	return func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc) {
		s := sessions.GetSession(r)

		if r.Method == "GET" {
			switch r.URL.Path {
			case PathLogin:
				login(c, s, w, r)
			case PathLogout:
				logout(s, w, r)
			case PathCallback:
				handleOAuth2Callback(c, s, w, r)
			default:
				next(w, r)
			}
		} else {
			next(w, r)
		}

	}
}
1234872
func (c *Config) SecurityProvider() string {
	val, ok := c.backend.Lookup("client.BCCSP.security.default.provider")
	if !ok {
		return strings.ToLower(defProvider)
	}
	return strings.ToLower(cast.ToString(val))
}
994572
func (p *providerImpl) provider() (*gooidc.Provider, error) {
	if p.goOIDCProvider != nil {
		return p.goOIDCProvider, nil
	}
	prov, err := p.newGoOIDCProvider()
	if err != nil {
		return nil, err
	}
	p.goOIDCProvider = prov
	return p.goOIDCProvider, nil
}
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))
	}
}
320492
func (op *OpenIDProvider) AuthURL(c Client, state string) string {
	values := url.Values{"client_id": {c.ISS}, "state": {state}, "response_type": {"code"},
		"redirect_uri": {c.RedirectURI}, "scope": {"openid profile email"}}
	return fmt.Sprintf("%s?%s", op.Config.AuthorizationEndpoint, values.Encode())
}
1303360
func (p *Provider) BeginAuth(state string) (goth.Session, error) {
	c := &oauth2.Config{
		Endpoint: oauth2.Endpoint{
			AuthURL: "http://example.com/auth",
		},
	}
	url := c.AuthCodeURL(state)
	return &Session{
		ID:      "id",
		AuthURL: url,
	}, nil
}
1156513
func Convert_v1_OpenIDIdentityProvider_To_config_OpenIDIdentityProvider(in *v1.OpenIDIdentityProvider, out *config.OpenIDIdentityProvider, s conversion.Scope) error {
	return autoConvert_v1_OpenIDIdentityProvider_To_config_OpenIDIdentityProvider(in, out, s)
}
166231
func WrapHandlerFuncForAuth(h http.HandlerFunc) http.HandlerFunc {
	return WrapHandlerFuncForAuthCreds(h, _adminuser, _adminpass, _authrealm)
}
739899
func getAuthenticateeProvider(name string) (provider Authenticatee, ok bool) {
	providerLock.Lock()
	defer providerLock.Unlock()

	provider, ok = authenticateeProviders[name]
	return
}
965906
func (p *OAuth) Wrapper(e *echo.Echo, middlewares ...interface{}) {
	p.Config.GenerateProviders()

	g := e.Group(p.Config.Path, middlewares...)

	// set the mux path to handle the registered providers
	g.Get("/login/:provider", p.beginAuthHandler)

	authMiddleware := func(h echo.Handler) echo.Handler {
		return echo.HandlerFunc(func(ctx echo.Context) error {
			user, err := p.completeAuthHandler(ctx)
			if err != nil {
				return echo.NewHTTPError(http.StatusUnauthorized, err.Error())
			}
			ctx.Set(p.Config.ContextKey, user)
			return h.Handle(ctx)
		})
	}

	p.successHandlers = append([]interface{}{authMiddleware}, p.successHandlers...)
	lastIndex := len(p.successHandlers) - 1
	if lastIndex == 0 {
		g.Get("/callback/:provider", func(ctx echo.Context) error {
			return ctx.String(`Success Handler is not set`)
		}, p.successHandlers...)
	} else {
		g.Get("/callback/:provider", p.successHandlers[lastIndex], p.successHandlers[0:lastIndex]...)
	}
	// register the error handler
	if p.failHandler != nil {
		e.SetHTTPErrorHandler(p.failHandler)
	}
}
432901
func NewDNSProvider() (*DNSProvider, error) {
	values, err := env.Get("CONOHA_TENANT_ID", "CONOHA_API_USERNAME", "CONOHA_API_PASSWORD")
	if err != nil {
		return nil, fmt.Errorf("conoha: %v", err)
	}

	config := NewDefaultConfig()
	config.TenantID = values["CONOHA_TENANT_ID"]
	config.Username = values["CONOHA_API_USERNAME"]
	config.Password = values["CONOHA_API_PASSWORD"]

	return NewDNSProviderConfig(config)
}