Browse Source

Merge pull request #26 from matrix-org/kegan/get-session

Add endpoint for GETing AuthSession information for a user/realm tuple
pull/29/head
Kegsay 8 years ago
committed by GitHub
parent
commit
a2290fc2ce
  1. 35
      src/github.com/matrix-org/go-neb/api.go
  2. 1
      src/github.com/matrix-org/go-neb/goneb.go
  3. 5
      src/github.com/matrix-org/go-neb/realms/github/github.go
  4. 5
      src/github.com/matrix-org/go-neb/realms/jira/jira.go
  5. 1
      src/github.com/matrix-org/go-neb/types/types.go

35
src/github.com/matrix-org/go-neb/api.go

@ -263,3 +263,38 @@ func (h *getServiceHandler) OnIncomingRequest(req *http.Request) (interface{}, *
Config types.Service Config types.Service
}{srv.ServiceID(), srv.ServiceType(), srv}, nil }{srv.ServiceID(), srv.ServiceType(), srv}, nil
} }
type getSessionHandler struct {
db *database.ServiceDB
}
func (h *getSessionHandler) OnIncomingRequest(req *http.Request) (interface{}, *errors.HTTPError) {
if req.Method != "POST" {
return nil, &errors.HTTPError{nil, "Unsupported Method", 405}
}
var body struct {
RealmID string
UserID string
}
if err := json.NewDecoder(req.Body).Decode(&body); err != nil {
return nil, &errors.HTTPError{err, "Error parsing request JSON", 400}
}
if body.RealmID == "" || body.UserID == "" {
return nil, &errors.HTTPError{nil, `Must supply a "RealmID" and "UserID"`, 400}
}
session, err := h.db.LoadAuthSessionByUser(body.RealmID, body.UserID)
if err != nil {
if err == sql.ErrNoRows {
return nil, &errors.HTTPError{err, `Session not found`, 404}
}
return nil, &errors.HTTPError{err, `Failed to load session`, 500}
}
return &struct {
ID string
Authenticated bool
Session types.AuthSession
}{session.ID(), session.Authenticated(), session}, nil
}

1
src/github.com/matrix-org/go-neb/goneb.go

@ -41,6 +41,7 @@ func main() {
http.Handle("/test", server.MakeJSONAPI(&heartbeatHandler{})) http.Handle("/test", server.MakeJSONAPI(&heartbeatHandler{}))
http.Handle("/admin/getService", server.MakeJSONAPI(&getServiceHandler{db: db})) http.Handle("/admin/getService", server.MakeJSONAPI(&getServiceHandler{db: db}))
http.Handle("/admin/getSession", server.MakeJSONAPI(&getSessionHandler{db: db}))
http.Handle("/admin/configureClient", server.MakeJSONAPI(&configureClientHandler{db: db, clients: clients})) http.Handle("/admin/configureClient", server.MakeJSONAPI(&configureClientHandler{db: db, clients: clients}))
http.Handle("/admin/configureService", server.MakeJSONAPI(&configureServiceHandler{db: db, clients: clients})) http.Handle("/admin/configureService", server.MakeJSONAPI(&configureServiceHandler{db: db, clients: clients}))
http.Handle("/admin/configureAuthRealm", server.MakeJSONAPI(&configureAuthRealmHandler{db: db})) http.Handle("/admin/configureAuthRealm", server.MakeJSONAPI(&configureAuthRealmHandler{db: db}))

5
src/github.com/matrix-org/go-neb/realms/github/github.go

@ -30,6 +30,11 @@ type GithubSession struct {
realmID string realmID string
} }
// Authenticated returns true if the user has completed the auth process
func (s *GithubSession) Authenticated() bool {
return s.AccessToken != ""
}
// UserID returns the user_id who authorised with Github // UserID returns the user_id who authorised with Github
func (s *GithubSession) UserID() string { func (s *GithubSession) UserID() string {
return s.userID return s.userID

5
src/github.com/matrix-org/go-neb/realms/jira/jira.go

@ -46,6 +46,11 @@ type JIRASession struct {
AccessSecret string AccessSecret string
} }
// Authenticated returns true if the user has completed the auth process
func (s *JIRASession) Authenticated() bool {
return s.AccessToken != "" && s.AccessSecret != ""
}
// UserID returns the ID of the user performing the authentication. // UserID returns the ID of the user performing the authentication.
func (s *JIRASession) UserID() string { func (s *JIRASession) UserID() string {
return s.userID return s.userID

1
src/github.com/matrix-org/go-neb/types/types.go

@ -123,4 +123,5 @@ type AuthSession interface {
ID() string ID() string
UserID() string UserID() string
RealmID() string RealmID() string
Authenticated() bool
} }
Loading…
Cancel
Save