Skip to content

Commit

Permalink
simplify gitlab oauth config
Browse files Browse the repository at this point in the history
  • Loading branch information
paddatrapper committed Mar 16, 2020
1 parent c292512 commit 26b6ed5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
2 changes: 2 additions & 0 deletions account.go
Expand Up @@ -309,6 +309,7 @@ func viewLogin(app *App, w http.ResponseWriter, r *http.Request) error {
OauthSlack bool
OauthWriteAs bool
OauthGitlab bool
GitlabHost string
}{
pageForReq(app, r),
r.FormValue("to"),
Expand All @@ -318,6 +319,7 @@ func viewLogin(app *App, w http.ResponseWriter, r *http.Request) error {
app.Config().SlackOauth.ClientID != "",
app.Config().WriteAsOauth.ClientID != "",
app.Config().GitlabOauth.ClientID != "",
config.OrDefaultString(app.Config().GitlabOauth.DisplayName, gitlabDisplayName),
}

if earlyError != "" {
Expand Down
5 changes: 2 additions & 3 deletions config/config.go
Expand Up @@ -72,9 +72,8 @@ type (
GitlabOauthCfg struct {
ClientID string `ini:"client_id"`
ClientSecret string `ini:"client_secret"`
AuthLocation string `ini:"auth_location"`
TokenLocation string `ini:"token_location"`
InspectLocation string `ini:"inspect_location"`
Host string `ini:"host"`
DisplayName string `ini:"display_name"`
CallbackProxy string `ini:"callback_proxy"`
CallbackProxyAPI string `ini:"callback_proxy_api"`
}
Expand Down
7 changes: 4 additions & 3 deletions oauth.go
Expand Up @@ -179,12 +179,13 @@ func configureGitlabOauth(parentHandler *Handler, r *mux.Router, app *App) {
callbackLocation = app.Config().GitlabOauth.CallbackProxy
}

address := config.OrDefaultString(app.Config().GitlabOauth.Host, gitlabHost)
oauthClient := gitlabOauthClient{
ClientID: app.Config().GitlabOauth.ClientID,
ClientSecret: app.Config().GitlabOauth.ClientSecret,
ExchangeLocation: config.OrDefaultString(app.Config().GitlabOauth.TokenLocation, gitlabExchangeLocation),
InspectLocation: config.OrDefaultString(app.Config().GitlabOauth.InspectLocation, gitlabIdentityLocation),
AuthLocation: config.OrDefaultString(app.Config().GitlabOauth.AuthLocation, gitlabAuthLocation),
ExchangeLocation: address + "/oauth/token",
InspectLocation: address + "/api/v4/user",
AuthLocation: address + "/oauth/authorize",
HttpClient: config.DefaultHTTPClient(),
CallbackLocation: callbackLocation,
}
Expand Down
5 changes: 2 additions & 3 deletions oauth_gitlab.go
Expand Up @@ -21,9 +21,8 @@ type gitlabOauthClient struct {
var _ oauthClient = gitlabOauthClient{}

const (
gitlabAuthLocation = "https://gitlab.com/oauth/authorize"
gitlabExchangeLocation = "https://gitlab.com/oauth/token"
gitlabIdentityLocation = "https://gitlab.com/api/v4/user"
gitlabHost = "https://gitlab.com"
gitlabDisplayName = "GitLab"
)

func (c gitlabOauthClient) GetProvider() string {
Expand Down
2 changes: 1 addition & 1 deletion pages/login.tmpl
Expand Up @@ -55,7 +55,7 @@ hr.short {
<a class="btn cta loginbtn" id="writeas-login" href="/oauth/write.as">Sign in with <strong>Write.as</strong></a>
{{ end }}
{{ if .OauthGitlab }}
<a class="btn cta loginbtn" id="gitlab-login" href="/oauth/gitlab">Sign in with <strong>GitLab</strong></a>
<a class="btn cta loginbtn" id="gitlab-login" href="/oauth/gitlab">Sign in with <strong>{{ .GitlabDisplayName }}</strong></a>
{{ end }}
</div>

Expand Down

0 comments on commit 26b6ed5

Please sign in to comment.