|
|
@ -12,11 +12,12 @@ import ( |
|
|
|
"net/url" |
|
|
|
) |
|
|
|
|
|
|
|
type githubRealm struct { |
|
|
|
type GithubRealm struct { |
|
|
|
id string |
|
|
|
redirectURL string |
|
|
|
ClientSecret string |
|
|
|
ClientID string |
|
|
|
StarterLink string |
|
|
|
} |
|
|
|
|
|
|
|
// GithubSession represents an authenticated github session
|
|
|
@ -45,23 +46,23 @@ func (s *GithubSession) ID() string { |
|
|
|
return s.id |
|
|
|
} |
|
|
|
|
|
|
|
func (r *githubRealm) ID() string { |
|
|
|
func (r *GithubRealm) ID() string { |
|
|
|
return r.id |
|
|
|
} |
|
|
|
|
|
|
|
func (r *githubRealm) Type() string { |
|
|
|
func (r *GithubRealm) Type() string { |
|
|
|
return "github" |
|
|
|
} |
|
|
|
|
|
|
|
func (r *githubRealm) Init() error { |
|
|
|
func (r *GithubRealm) Init() error { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func (r *githubRealm) Register() error { |
|
|
|
func (r *GithubRealm) Register() error { |
|
|
|
return nil |
|
|
|
} |
|
|
|
|
|
|
|
func (r *githubRealm) RequestAuthSession(userID string, req json.RawMessage) interface{} { |
|
|
|
func (r *GithubRealm) RequestAuthSession(userID string, req json.RawMessage) interface{} { |
|
|
|
state, err := randomString(10) |
|
|
|
if err != nil { |
|
|
|
log.WithError(err).Print("Failed to generate state param") |
|
|
@ -90,7 +91,7 @@ func (r *githubRealm) RequestAuthSession(userID string, req json.RawMessage) int |
|
|
|
}{u.String()} |
|
|
|
} |
|
|
|
|
|
|
|
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
|
|
|
|
code := req.URL.Query().Get("code") |
|
|
|
state := req.URL.Query().Get("state") |
|
|
@ -148,7 +149,7 @@ func (r *githubRealm) OnReceiveRedirect(w http.ResponseWriter, req *http.Request |
|
|
|
w.Write([]byte("OK!")) |
|
|
|
} |
|
|
|
|
|
|
|
func (r *githubRealm) AuthSession(id, userID, realmID string) types.AuthSession { |
|
|
|
func (r *GithubRealm) AuthSession(id, userID, realmID string) types.AuthSession { |
|
|
|
return &GithubSession{ |
|
|
|
id: id, |
|
|
|
userID: userID, |
|
|
@ -175,6 +176,6 @@ func randomString(length int) (string, error) { |
|
|
|
|
|
|
|
func init() { |
|
|
|
types.RegisterAuthRealm(func(realmID, redirectURL string) types.AuthRealm { |
|
|
|
return &githubRealm{id: realmID, redirectURL: redirectURL} |
|
|
|
return &GithubRealm{id: realmID, redirectURL: redirectURL} |
|
|
|
}) |
|
|
|
} |