Merge pull request #283 from writeas/gitlab-oauth-cleanup
Clean up GitLab auth code
This commit is contained in:
commit
75a9df82ab
5 changed files with 13 additions and 13 deletions
16
account.go
16
account.go
|
@ -302,14 +302,14 @@ func viewLogin(app *App, w http.ResponseWriter, r *http.Request) error {
|
||||||
|
|
||||||
p := &struct {
|
p := &struct {
|
||||||
page.StaticPage
|
page.StaticPage
|
||||||
To string
|
To string
|
||||||
Message template.HTML
|
Message template.HTML
|
||||||
Flashes []template.HTML
|
Flashes []template.HTML
|
||||||
LoginUsername string
|
LoginUsername string
|
||||||
OauthSlack bool
|
OauthSlack bool
|
||||||
OauthWriteAs bool
|
OauthWriteAs bool
|
||||||
OauthGitlab bool
|
OauthGitlab bool
|
||||||
GitlabHost string
|
GitlabDisplayName string
|
||||||
}{
|
}{
|
||||||
pageForReq(app, r),
|
pageForReq(app, r),
|
||||||
r.FormValue("to"),
|
r.FormValue("to"),
|
||||||
|
|
|
@ -2512,7 +2512,7 @@ func (db *datastore) GetCollectionLastPostTime(id int64) (*time.Time, error) {
|
||||||
|
|
||||||
func (db *datastore) GenerateOAuthState(ctx context.Context, provider, clientID string) (string, error) {
|
func (db *datastore) GenerateOAuthState(ctx context.Context, provider, clientID string) (string, error) {
|
||||||
state := store.Generate62RandomString(24)
|
state := store.Generate62RandomString(24)
|
||||||
_, err := db.ExecContext(ctx, "INSERT INTO oauth_client_states (state, provider, client_id, used, created_at) VALUES (?, ?, ?, FALSE, " + db.now() + ")", state, provider, clientID)
|
_, err := db.ExecContext(ctx, "INSERT INTO oauth_client_states (state, provider, client_id, used, created_at) VALUES (?, ?, ?, FALSE, "+db.now()+")", state, provider, clientID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("unable to record oauth client state: %w", err)
|
return "", fmt.Errorf("unable to record oauth client state: %w", err)
|
||||||
}
|
}
|
||||||
|
|
2
oauth.go
2
oauth.go
|
@ -179,7 +179,7 @@ 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)
|
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,
|
||||||
|
|
|
@ -21,8 +21,8 @@ type gitlabOauthClient struct {
|
||||||
var _ oauthClient = gitlabOauthClient{}
|
var _ oauthClient = gitlabOauthClient{}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
gitlabHost = "https://gitlab.com"
|
gitlabHost = "https://gitlab.com"
|
||||||
gitlabDisplayName = "GitLab"
|
gitlabDisplayName = "GitLab"
|
||||||
)
|
)
|
||||||
|
|
||||||
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>{{ .GitlabDisplayName }}</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