(config *codersdk.ExternalAuthConfig)
| 1081 | } |
| 1082 | |
| 1083 | func bitbucketServerDefaults(config *codersdk.ExternalAuthConfig) codersdk.ExternalAuthConfig { |
| 1084 | defaults := codersdk.ExternalAuthConfig{ |
| 1085 | DisplayName: "Bitbucket Server", |
| 1086 | Scopes: []string{"PUBLIC_REPOS", "REPO_READ", "REPO_WRITE"}, |
| 1087 | DisplayIcon: "/icon/bitbucket.svg", |
| 1088 | // TODO: Investigate if 'S256' is accepted and PKCE is supported |
| 1089 | CodeChallengeMethodsSupported: []string{string(promoauth.PKCEChallengeMethodNone)}, |
| 1090 | } |
| 1091 | // Bitbucket servers will have some base url, e.g. https://bitbucket.coder.com. |
| 1092 | // We will grab this from the Auth URL. This choice is a bit arbitrary, |
| 1093 | // but we need to require at least 1 field to be populated. |
| 1094 | if config.AuthURL == "" { |
| 1095 | // No auth url, means we cannot guess the urls. |
| 1096 | return defaults |
| 1097 | } |
| 1098 | |
| 1099 | auth, err := url.Parse(config.AuthURL) |
| 1100 | if err != nil { |
| 1101 | // We need a valid URL to continue with. |
| 1102 | return defaults |
| 1103 | } |
| 1104 | |
| 1105 | // Populate Regex, ValidateURL, and TokenURL. |
| 1106 | // Default regex should be anything using the same host as the auth url. |
| 1107 | defaults.Regex = fmt.Sprintf(`^(https?://)?%s(/.*)?$`, strings.ReplaceAll(auth.Host, ".", `\.`)) |
| 1108 | |
| 1109 | tokenURL := auth.ResolveReference(&url.URL{Path: "/rest/oauth2/latest/token"}) |
| 1110 | defaults.TokenURL = tokenURL.String() |
| 1111 | |
| 1112 | // validate needs to return a 200 when logged in and a 401 when unauthenticated. |
| 1113 | // This endpoint returns the count of the number of PR's in the authenticated |
| 1114 | // user's inbox. Which will work perfectly for our use case. |
| 1115 | validate := auth.ResolveReference(&url.URL{Path: "/rest/api/latest/inbox/pull-requests/count"}) |
| 1116 | defaults.ValidateURL = validate.String() |
| 1117 | |
| 1118 | return defaults |
| 1119 | } |
| 1120 | |
| 1121 | // gitlabDefaults returns a static config if using the gitlab cloud offering. |
| 1122 | // The values are dynamic if using a self-hosted gitlab. |
no test coverage detected