From 9adb89c24d10dbb391c4d623940fad717bf53495 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 5 Aug 2016 11:17:07 +0100 Subject: [PATCH] Start parsing out redirect requests for github realms --- src/github.com/matrix-org/go-neb/database/db.go | 5 +++-- .../matrix-org/go-neb/realms/github/github.go | 11 +++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) 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 {