diff --git a/src/github.com/matrix-org/go-neb/database/db.go b/src/github.com/matrix-org/go-neb/database/db.go index 9ade230..de4741d 100644 --- a/src/github.com/matrix-org/go-neb/database/db.go +++ b/src/github.com/matrix-org/go-neb/database/db.go @@ -218,9 +218,10 @@ func (d *ServiceDB) StoreAuthSession(session types.AuthSession) (old types.AuthS return } -// LoadAuthSession loads an AuthSession from the database. +// LoadAuthSessionForUser loads an AuthSession from the database based on the given +// realm and user ID. // Returns sql.ErrNoRows if the session isn't in the database. -func (d *ServiceDB) LoadAuthSession(realmID, userID string) (session types.AuthSession, err error) { +func (d *ServiceDB) LoadAuthSessionForUser(realmID, userID string) (session types.AuthSession, err error) { err = runTransaction(d.db, func(txn *sql.Tx) error { session, err = selectAuthSessionTxn(txn, realmID, userID) return err diff --git a/src/github.com/matrix-org/go-neb/realms/github/github.go b/src/github.com/matrix-org/go-neb/realms/github/github.go index aaf7a67..b763768 100644 --- a/src/github.com/matrix-org/go-neb/realms/github/github.go +++ b/src/github.com/matrix-org/go-neb/realms/github/github.go @@ -71,6 +71,17 @@ func (r *githubRealm) RequestAuthSession(userID string, req json.RawMessage) int } func (r *githubRealm) OnReceiveRedirect(w http.ResponseWriter, req *http.Request) { + code := req.URL.Query().Get("code") + state := req.URL.Query().Get("state") + log.WithFields(log.Fields{ + "code": code, + "state": state, + }).Print("GithubRealm: OnReceiveRedirect") + if code == "" || state == "" { + w.WriteHeader(400) + w.Write([]byte("code and state are required")) + return + } } func (r *githubRealm) AuthSession(userID, realmID string) types.AuthSession {