Exemple #1
0
func (of OAuthFactory) GetProviders(teamName string) (Providers, error) {
	team, found, err := of.db.GetTeamByName(teamName)
	if err != nil {
		return Providers{}, err
	}
	if !found {
		return Providers{}, errors.New("team not found")
	}

	providers := Providers{}

	if len(team.GitHubAuth.Organizations) > 0 ||
		len(team.GitHubAuth.Teams) > 0 ||
		len(team.GitHubAuth.Users) > 0 {

		redirectURL, err := of.routes.CreatePathForRoute(of.callback, rata.Params{
			"provider": github.ProviderName,
		})
		if err != nil {
			return Providers{}, err
		}
		gitHubAuthProvider := github.NewProvider(team.GitHubAuth, urljoiner.Join(of.atcExternalURL, redirectURL))

		providers[github.ProviderName] = gitHubAuthProvider
	}

	return providers, err
}
Exemple #2
0
func (cmd *ATCCommand) configureOAuthProviders(logger lager.Logger) (auth.Providers, error) {
	oauthProviders := auth.Providers{}

	gitHubAuthMethods := []github.AuthorizationMethod{}
	for _, org := range cmd.GitHubAuth.Organizations {
		gitHubAuthMethods = append(gitHubAuthMethods, github.AuthorizationMethod{
			Organization: org,
		})
	}

	for _, team := range cmd.GitHubAuth.Teams {
		gitHubAuthMethods = append(gitHubAuthMethods, github.AuthorizationMethod{
			Team:         team.TeamName,
			Organization: team.OrganizationName,
		})
	}

	for _, user := range cmd.GitHubAuth.Users {
		gitHubAuthMethods = append(gitHubAuthMethods, github.AuthorizationMethod{
			User: user,
		})
	}

	if len(gitHubAuthMethods) > 0 {
		path, err := auth.OAuthRoutes.CreatePathForRoute(auth.OAuthCallback, rata.Params{
			"provider": github.ProviderName,
		})
		if err != nil {
			return nil, err
		}

		oauthProviders[github.ProviderName] = github.NewProvider(
			gitHubAuthMethods,
			cmd.GitHubAuth.ClientID,
			cmd.GitHubAuth.ClientSecret,
			cmd.ExternalURL.String()+path,
		)
	}

	return oauthProviders, nil
}