Browse Source

Comments

pull/27/head
Kegan Dougal 8 years ago
parent
commit
2a93bbee82
  1. 8
      src/github.com/matrix-org/go-neb/realms/github/github.go

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

@ -12,6 +12,7 @@ import (
"net/url" "net/url"
) )
// GithubRealm can handle OAuth processes with github.com
type GithubRealm struct { type GithubRealm struct {
id string id string
redirectURL string redirectURL string
@ -46,22 +47,27 @@ func (s *GithubSession) ID() string {
return s.id return s.id
} }
// ID returns the realm ID
func (r *GithubRealm) ID() string { func (r *GithubRealm) ID() string {
return r.id return r.id
} }
// Type is github
func (r *GithubRealm) Type() string { func (r *GithubRealm) Type() string {
return "github" return "github"
} }
// Init does nothing.
func (r *GithubRealm) Init() error { func (r *GithubRealm) Init() error {
return nil return nil
} }
// Register does nothing.
func (r *GithubRealm) Register() error { func (r *GithubRealm) Register() error {
return nil return nil
} }
// RequestAuthSession generates an OAuth2 URL for this user to auth with github via.
func (r *GithubRealm) RequestAuthSession(userID string, req json.RawMessage) interface{} { func (r *GithubRealm) RequestAuthSession(userID string, req json.RawMessage) interface{} {
state, err := randomString(10) state, err := randomString(10)
if err != nil { if err != nil {
@ -91,6 +97,7 @@ func (r *GithubRealm) RequestAuthSession(userID string, req json.RawMessage) int
}{u.String()} }{u.String()}
} }
// OnReceiveRedirect processes OAuth redirect requests from Github
func (r *GithubRealm) OnReceiveRedirect(w http.ResponseWriter, req *http.Request) { func (r *GithubRealm) OnReceiveRedirect(w http.ResponseWriter, req *http.Request) {
// parse out params from the request // parse out params from the request
code := req.URL.Query().Get("code") code := req.URL.Query().Get("code")
@ -149,6 +156,7 @@ func (r *GithubRealm) OnReceiveRedirect(w http.ResponseWriter, req *http.Request
w.Write([]byte("OK!")) w.Write([]byte("OK!"))
} }
// AuthSession returns a GithubSession for this user
func (r *GithubRealm) AuthSession(id, userID, realmID string) types.AuthSession { func (r *GithubRealm) AuthSession(id, userID, realmID string) types.AuthSession {
return &GithubSession{ return &GithubSession{
id: id, id: id,

Loading…
Cancel
Save