simplify gitlab oauth config
This commit is contained in:
parent
c292512b9d
commit
26b6ed5f4f
5 changed files with 11 additions and 10 deletions
|
@ -309,6 +309,7 @@ func viewLogin(app *App, w http.ResponseWriter, r *http.Request) error {
|
||||||
OauthSlack bool
|
OauthSlack bool
|
||||||
OauthWriteAs bool
|
OauthWriteAs bool
|
||||||
OauthGitlab bool
|
OauthGitlab bool
|
||||||
|
GitlabHost string
|
||||||
}{
|
}{
|
||||||
pageForReq(app, r),
|
pageForReq(app, r),
|
||||||
r.FormValue("to"),
|
r.FormValue("to"),
|
||||||
|
@ -318,6 +319,7 @@ func viewLogin(app *App, w http.ResponseWriter, r *http.Request) error {
|
||||||
app.Config().SlackOauth.ClientID != "",
|
app.Config().SlackOauth.ClientID != "",
|
||||||
app.Config().WriteAsOauth.ClientID != "",
|
app.Config().WriteAsOauth.ClientID != "",
|
||||||
app.Config().GitlabOauth.ClientID != "",
|
app.Config().GitlabOauth.ClientID != "",
|
||||||
|
config.OrDefaultString(app.Config().GitlabOauth.DisplayName, gitlabDisplayName),
|
||||||
}
|
}
|
||||||
|
|
||||||
if earlyError != "" {
|
if earlyError != "" {
|
||||||
|
|
|
@ -72,9 +72,8 @@ type (
|
||||||
GitlabOauthCfg struct {
|
GitlabOauthCfg struct {
|
||||||
ClientID string `ini:"client_id"`
|
ClientID string `ini:"client_id"`
|
||||||
ClientSecret string `ini:"client_secret"`
|
ClientSecret string `ini:"client_secret"`
|
||||||
AuthLocation string `ini:"auth_location"`
|
Host string `ini:"host"`
|
||||||
TokenLocation string `ini:"token_location"`
|
DisplayName string `ini:"display_name"`
|
||||||
InspectLocation string `ini:"inspect_location"`
|
|
||||||
CallbackProxy string `ini:"callback_proxy"`
|
CallbackProxy string `ini:"callback_proxy"`
|
||||||
CallbackProxyAPI string `ini:"callback_proxy_api"`
|
CallbackProxyAPI string `ini:"callback_proxy_api"`
|
||||||
}
|
}
|
||||||
|
|
7
oauth.go
7
oauth.go
|
@ -179,12 +179,13 @@ func configureGitlabOauth(parentHandler *Handler, r *mux.Router, app *App) {
|
||||||
callbackLocation = app.Config().GitlabOauth.CallbackProxy
|
callbackLocation = app.Config().GitlabOauth.CallbackProxy
|
||||||
}
|
}
|
||||||
|
|
||||||
|
address := config.OrDefaultString(app.Config().GitlabOauth.Host, gitlabHost)
|
||||||
oauthClient := gitlabOauthClient{
|
oauthClient := gitlabOauthClient{
|
||||||
ClientID: app.Config().GitlabOauth.ClientID,
|
ClientID: app.Config().GitlabOauth.ClientID,
|
||||||
ClientSecret: app.Config().GitlabOauth.ClientSecret,
|
ClientSecret: app.Config().GitlabOauth.ClientSecret,
|
||||||
ExchangeLocation: config.OrDefaultString(app.Config().GitlabOauth.TokenLocation, gitlabExchangeLocation),
|
ExchangeLocation: address + "/oauth/token",
|
||||||
InspectLocation: config.OrDefaultString(app.Config().GitlabOauth.InspectLocation, gitlabIdentityLocation),
|
InspectLocation: address + "/api/v4/user",
|
||||||
AuthLocation: config.OrDefaultString(app.Config().GitlabOauth.AuthLocation, gitlabAuthLocation),
|
AuthLocation: address + "/oauth/authorize",
|
||||||
HttpClient: config.DefaultHTTPClient(),
|
HttpClient: config.DefaultHTTPClient(),
|
||||||
CallbackLocation: callbackLocation,
|
CallbackLocation: callbackLocation,
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,9 +21,8 @@ type gitlabOauthClient struct {
|
||||||
var _ oauthClient = gitlabOauthClient{}
|
var _ oauthClient = gitlabOauthClient{}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
gitlabAuthLocation = "https://gitlab.com/oauth/authorize"
|
gitlabHost = "https://gitlab.com"
|
||||||
gitlabExchangeLocation = "https://gitlab.com/oauth/token"
|
gitlabDisplayName = "GitLab"
|
||||||
gitlabIdentityLocation = "https://gitlab.com/api/v4/user"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (c gitlabOauthClient) GetProvider() string {
|
func (c gitlabOauthClient) GetProvider() string {
|
||||||
|
|
|
@ -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>
|
<a class="btn cta loginbtn" id="writeas-login" href="/oauth/write.as">Sign in with <strong>Write.as</strong></a>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ if .OauthGitlab }}
|
{{ 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 }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue