From 2a93bbee8220891c2c233d0bf3c735f58d8e9cd9 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 15 Aug 2016 11:27:37 +0100 Subject: [PATCH] Comments --- src/github.com/matrix-org/go-neb/realms/github/github.go | 8 ++++++++ 1 file changed, 8 insertions(+) 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 3e54c7e..f1c1021 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 @@ -12,6 +12,7 @@ import ( "net/url" ) +// GithubRealm can handle OAuth processes with github.com type GithubRealm struct { id string redirectURL string @@ -46,22 +47,27 @@ func (s *GithubSession) ID() string { return s.id } +// ID returns the realm ID func (r *GithubRealm) ID() string { return r.id } +// Type is github func (r *GithubRealm) Type() string { return "github" } +// Init does nothing. func (r *GithubRealm) Init() error { return nil } +// Register does nothing. func (r *GithubRealm) Register() error { 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{} { state, err := randomString(10) if err != nil { @@ -91,6 +97,7 @@ func (r *GithubRealm) RequestAuthSession(userID string, req json.RawMessage) int }{u.String()} } +// OnReceiveRedirect processes OAuth redirect requests from Github func (r *GithubRealm) OnReceiveRedirect(w http.ResponseWriter, req *http.Request) { // parse out params from the request code := req.URL.Query().Get("code") @@ -149,6 +156,7 @@ func (r *GithubRealm) OnReceiveRedirect(w http.ResponseWriter, req *http.Request w.Write([]byte("OK!")) } +// AuthSession returns a GithubSession for this user func (r *GithubRealm) AuthSession(id, userID, realmID string) types.AuthSession { return &GithubSession{ id: id,