MCPcopy Index your code
hub / github.com/coder/coder / getGithubOAuth2ConfigParams

Function getGithubOAuth2ConfigParams

cli/server.go:2139–2179  ·  view source on GitHub ↗
(ctx context.Context, db database.Store, vals *codersdk.DeploymentValues)

Source from the content-addressed store, hash-verified

2137}
2138
2139func getGithubOAuth2ConfigParams(ctx context.Context, db database.Store, vals *codersdk.DeploymentValues) (*githubOAuth2ConfigParams, error) {
2140 params := githubOAuth2ConfigParams{
2141 accessURL: vals.AccessURL.Value(),
2142 clientID: vals.OAuth2.Github.ClientID.String(),
2143 clientSecret: vals.OAuth2.Github.ClientSecret.String(),
2144 deviceFlow: vals.OAuth2.Github.DeviceFlow.Value(),
2145 allowSignups: vals.OAuth2.Github.AllowSignups.Value(),
2146 allowEveryone: vals.OAuth2.Github.AllowEveryone.Value(),
2147 allowOrgs: vals.OAuth2.Github.AllowedOrgs.Value(),
2148 rawTeams: vals.OAuth2.Github.AllowedTeams.Value(),
2149 enterpriseBaseURL: vals.OAuth2.Github.EnterpriseBaseURL.String(),
2150 }
2151
2152 // If the user manually configured the GitHub OAuth2 provider,
2153 // we won't add the default configuration.
2154 if params.clientID != "" || params.clientSecret != "" || params.enterpriseBaseURL != "" {
2155 return &params, nil
2156 }
2157
2158 // Check if the user manually disabled the default GitHub OAuth2 provider.
2159 if !vals.OAuth2.Github.DefaultProviderEnable.Value() {
2160 return nil, nil //nolint:nilnil
2161 }
2162
2163 defaultEligible, err := isDeploymentEligibleForGithubDefaultProvider(ctx, db)
2164 if err != nil {
2165 return nil, err
2166 }
2167
2168 if !defaultEligible {
2169 return nil, nil //nolint:nilnil
2170 }
2171
2172 params.clientID = GithubOAuth2DefaultProviderClientID
2173 params.deviceFlow = GithubOAuth2DefaultProviderDeviceFlow
2174 if len(params.allowOrgs) == 0 {
2175 params.allowEveryone = GithubOAuth2DefaultProviderAllowEveryone
2176 }
2177
2178 return &params, nil
2179}
2180
2181func configureGithubOAuth2(instrument *promoauth.Factory, params *githubOAuth2ConfigParams) (*coderd.GithubOAuth2Config, error) {
2182 redirectURL, err := params.accessURL.Parse("/api/v2/users/oauth2/github/callback")

Callers 1

ServerMethod · 0.85

Calls 3

ValueMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected