Browse Source

Start parsing out redirect requests for github realms

kegan/github-auth
Kegan Dougal 9 years ago
parent
commit
9adb89c24d
  1. 5
      src/github.com/matrix-org/go-neb/database/db.go
  2. 11
      src/github.com/matrix-org/go-neb/realms/github/github.go

5
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

11
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 {

Loading…
Cancel
Save