api: add github oauth

Closes https://gitlab.com/commento/commento/issues/20
This commit is contained in:
Adhityaa Chandrasekar
2019-01-30 21:15:16 -05:00
parent 24d76c2fb6
commit 55f24b2de2
8 changed files with 200 additions and 1 deletions

View File

@@ -0,0 +1,25 @@
package main
import (
"fmt"
"net/http"
)
func githubRedirectHandler(w http.ResponseWriter, r *http.Request) {
if githubConfig == nil {
logger.Errorf("github oauth access attempt without configuration")
fmt.Fprintf(w, "error: this website has not configured github OAuth")
return
}
commenterToken := r.FormValue("commenterToken")
_, err := commenterGetByCommenterToken(commenterToken)
if err != nil && err != errorNoSuchToken {
fmt.Fprintf(w, "error: %s\n", err.Error())
return
}
url := githubConfig.AuthCodeURL(commenterToken)
http.Redirect(w, r, url, http.StatusFound)
}