fixes and casing
This commit is contained in:
parent
cd8a983bdd
commit
5ea0476107
|
@ -14,18 +14,18 @@ import (
|
||||||
// ConsentReqDoer fetches information on the OAuth2 request and then accept or reject the requested authentication process.
|
// ConsentReqDoer fetches information on the OAuth2 request and then accept or reject the requested authentication process.
|
||||||
type ConsentReqDoer struct {
|
type ConsentReqDoer struct {
|
||||||
hydraURL string
|
hydraURL string
|
||||||
fakeTlsTermination bool
|
fakeTLSTermination bool
|
||||||
rememberFor int
|
rememberFor int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewConsentReqDoer creates a ConsentRequest.
|
// NewConsentReqDoer creates a ConsentRequest.
|
||||||
func NewConsentReqDoer(hydraURL string, fakeTlsTermination bool, rememberFor int) *ConsentReqDoer {
|
func NewConsentReqDoer(hydraURL string, fakeTLSTermination bool, rememberFor int) *ConsentReqDoer {
|
||||||
return &ConsentReqDoer{hydraURL: hydraURL, fakeTlsTermination: fakeTlsTermination, rememberFor: rememberFor}
|
return &ConsentReqDoer{hydraURL: hydraURL, fakeTLSTermination: fakeTLSTermination, rememberFor: rememberFor}
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitiateRequest fetches information on the OAuth2 request.
|
// InitiateRequest fetches information on the OAuth2 request.
|
||||||
func (crd *ConsentReqDoer) InitiateRequest(challenge string) (*ReqInfo, error) {
|
func (crd *ConsentReqDoer) InitiateRequest(challenge string) (*ReqInfo, error) {
|
||||||
ri, err := initiateRequest(consent, crd.hydraURL, crd.fakeTlsTermination, challenge)
|
ri, err := initiateRequest(consent, crd.hydraURL, crd.fakeTLSTermination, challenge)
|
||||||
return ri, errors.Wrap(err, "failed to initiate consent request")
|
return ri, errors.Wrap(err, "failed to initiate consent request")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,6 @@ func (crd *ConsentReqDoer) AcceptConsentRequest(challenge string, remember bool,
|
||||||
IDToken: idToken,
|
IDToken: idToken,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
redirectURI, err := acceptRequest(consent, crd.hydraURL, crd.fakeTlsTermination, challenge, data)
|
redirectURI, err := acceptRequest(consent, crd.hydraURL, crd.fakeTLSTermination, challenge, data)
|
||||||
return redirectURI, errors.Wrap(err, "failed to accept consent request")
|
return redirectURI, errors.Wrap(err, "failed to accept consent request")
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,7 +55,7 @@ func TestInitiateConsentRequest(t *testing.T) {
|
||||||
h := &testInitiateConsentHandler{reqInfo: tc.reqInfo, status: tc.status}
|
h := &testInitiateConsentHandler{reqInfo: tc.reqInfo, status: tc.status}
|
||||||
srv := httptest.NewServer(h)
|
srv := httptest.NewServer(h)
|
||||||
defer srv.Close()
|
defer srv.Close()
|
||||||
ldr := hydra.NewConsentReqDoer(srv.URL, tc.rememberFor)
|
ldr := hydra.NewConsentReqDoer(srv.URL, false, tc.rememberFor)
|
||||||
|
|
||||||
reqInfo, err := ldr.InitiateRequest(tc.challenge)
|
reqInfo, err := ldr.InitiateRequest(tc.challenge)
|
||||||
|
|
||||||
|
@ -149,7 +149,7 @@ func TestAcceptConsentRequest(t *testing.T) {
|
||||||
h := &testAcceptConsentHandler{challenge: tc.challenge, status: tc.status, redirect: tc.redirect}
|
h := &testAcceptConsentHandler{challenge: tc.challenge, status: tc.status, redirect: tc.redirect}
|
||||||
srv := httptest.NewServer(h)
|
srv := httptest.NewServer(h)
|
||||||
defer srv.Close()
|
defer srv.Close()
|
||||||
ldr := hydra.NewConsentReqDoer(srv.URL, tc.rememberFor)
|
ldr := hydra.NewConsentReqDoer(srv.URL, false, tc.rememberFor)
|
||||||
|
|
||||||
var grantScope []string
|
var grantScope []string
|
||||||
for _, v := range tc.grantScope {
|
for _, v := range tc.grantScope {
|
||||||
|
|
|
@ -44,7 +44,7 @@ type ReqInfo struct {
|
||||||
Subject string `json:"subject"`
|
Subject string `json:"subject"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func initiateRequest(typ reqType, hydraURL string, fakeTlsTermination bool, challenge string) (*ReqInfo, error) {
|
func initiateRequest(typ reqType, hydraURL string, fakeTLSTermination bool, challenge string) (*ReqInfo, error) {
|
||||||
if challenge == "" {
|
if challenge == "" {
|
||||||
return nil, ErrChallengeMissed
|
return nil, ErrChallengeMissed
|
||||||
}
|
}
|
||||||
|
@ -62,7 +62,7 @@ func initiateRequest(typ reqType, hydraURL string, fakeTlsTermination bool, chal
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if fakeTlsTermination {
|
if fakeTLSTermination {
|
||||||
req.Header.Add("X-Forwarded-Proto", "https")
|
req.Header.Add("X-Forwarded-Proto", "https")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ func initiateRequest(typ reqType, hydraURL string, fakeTlsTermination bool, chal
|
||||||
return &ri, nil
|
return &ri, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func acceptRequest(typ reqType, hydraURL string, fakeTlsTermination bool, challenge string, data interface{}) (string, error) {
|
func acceptRequest(typ reqType, hydraURL string, fakeTLSTermination bool, challenge string, data interface{}) (string, error) {
|
||||||
if challenge == "" {
|
if challenge == "" {
|
||||||
return "", ErrChallengeMissed
|
return "", ErrChallengeMissed
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ func acceptRequest(typ reqType, hydraURL string, fakeTlsTermination bool, challe
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
if fakeTlsTermination {
|
if fakeTLSTermination {
|
||||||
r.Header.Add("X-Forwarded-Proto", "https")
|
r.Header.Add("X-Forwarded-Proto", "https")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,18 +14,18 @@ import (
|
||||||
// LoginReqDoer fetches information on the OAuth2 request and then accept or reject the requested authentication process.
|
// LoginReqDoer fetches information on the OAuth2 request and then accept or reject the requested authentication process.
|
||||||
type LoginReqDoer struct {
|
type LoginReqDoer struct {
|
||||||
hydraURL string
|
hydraURL string
|
||||||
fakeTlsTermination bool
|
fakeTLSTermination bool
|
||||||
rememberFor int
|
rememberFor int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLoginReqDoer creates a LoginRequest.
|
// NewLoginReqDoer creates a LoginRequest.
|
||||||
func NewLoginReqDoer(hydraURL string, fakeTlsTermination bool, rememberFor int) *LoginReqDoer {
|
func NewLoginReqDoer(hydraURL string, fakeTLSTermination bool, rememberFor int) *LoginReqDoer {
|
||||||
return &LoginReqDoer{hydraURL: hydraURL, fakeTlsTermination: fakeTlsTermination, rememberFor: rememberFor}
|
return &LoginReqDoer{hydraURL: hydraURL, fakeTLSTermination: fakeTLSTermination, rememberFor: rememberFor}
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitiateRequest fetches information on the OAuth2 request.
|
// InitiateRequest fetches information on the OAuth2 request.
|
||||||
func (lrd *LoginReqDoer) InitiateRequest(challenge string) (*ReqInfo, error) {
|
func (lrd *LoginReqDoer) InitiateRequest(challenge string) (*ReqInfo, error) {
|
||||||
ri, err := initiateRequest(login, lrd.hydraURL, lrd.fakeTlsTermination, challenge)
|
ri, err := initiateRequest(login, lrd.hydraURL, lrd.fakeTLSTermination, challenge)
|
||||||
return ri, errors.Wrap(err, "failed to initiate login request")
|
return ri, errors.Wrap(err, "failed to initiate login request")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,6 +40,6 @@ func (lrd *LoginReqDoer) AcceptLoginRequest(challenge string, remember bool, sub
|
||||||
RememberFor: lrd.rememberFor,
|
RememberFor: lrd.rememberFor,
|
||||||
Subject: subject,
|
Subject: subject,
|
||||||
}
|
}
|
||||||
redirectURI, err := acceptRequest(login, lrd.hydraURL, lrd.fakeTlsTermination, challenge, data)
|
redirectURI, err := acceptRequest(login, lrd.hydraURL, lrd.fakeTLSTermination, challenge, data)
|
||||||
return redirectURI, errors.Wrap(err, "failed to accept login request")
|
return redirectURI, errors.Wrap(err, "failed to accept login request")
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,7 +60,7 @@ func TestInitiateLoginRequest(t *testing.T) {
|
||||||
h := &testInitiateLoginHandler{reqInfo: tc.reqInfo, status: tc.status}
|
h := &testInitiateLoginHandler{reqInfo: tc.reqInfo, status: tc.status}
|
||||||
srv := httptest.NewServer(h)
|
srv := httptest.NewServer(h)
|
||||||
defer srv.Close()
|
defer srv.Close()
|
||||||
ldr := hydra.NewLoginReqDoer(srv.URL, 0)
|
ldr := hydra.NewLoginReqDoer(srv.URL, false, 0)
|
||||||
|
|
||||||
reqInfo, err := ldr.InitiateRequest(tc.challenge)
|
reqInfo, err := ldr.InitiateRequest(tc.challenge)
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ func TestAcceptLoginRequest(t *testing.T) {
|
||||||
h := &testAcceptLoginHandler{challenge: tc.challenge, status: tc.status, redirect: tc.redirect}
|
h := &testAcceptLoginHandler{challenge: tc.challenge, status: tc.status, redirect: tc.redirect}
|
||||||
srv := httptest.NewServer(h)
|
srv := httptest.NewServer(h)
|
||||||
defer srv.Close()
|
defer srv.Close()
|
||||||
ldr := hydra.NewLoginReqDoer(srv.URL, tc.rememberFor)
|
ldr := hydra.NewLoginReqDoer(srv.URL, false, tc.rememberFor)
|
||||||
|
|
||||||
redirect, err := ldr.AcceptLoginRequest(tc.challenge, tc.remember, tc.subject)
|
redirect, err := ldr.AcceptLoginRequest(tc.challenge, tc.remember, tc.subject)
|
||||||
|
|
||||||
|
|
|
@ -14,22 +14,22 @@ import (
|
||||||
// LogoutReqDoer fetches information on the OAuth2 request and then accepts or rejects the requested logout process.
|
// LogoutReqDoer fetches information on the OAuth2 request and then accepts or rejects the requested logout process.
|
||||||
type LogoutReqDoer struct {
|
type LogoutReqDoer struct {
|
||||||
hydraURL string
|
hydraURL string
|
||||||
fakeTlsTermination bool
|
fakeTLSTermination bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLogoutReqDoer creates a LogoutRequest.
|
// NewLogoutReqDoer creates a LogoutRequest.
|
||||||
func NewLogoutReqDoer(hydraURL string, fakeTlsTermination bool) *LogoutReqDoer {
|
func NewLogoutReqDoer(hydraURL string, fakeTLSTermination bool) *LogoutReqDoer {
|
||||||
return &LogoutReqDoer{hydraURL: hydraURL, fakeTlsTermination: fakeTlsTermination}
|
return &LogoutReqDoer{hydraURL: hydraURL, fakeTLSTermination: fakeTLSTermination}
|
||||||
}
|
}
|
||||||
|
|
||||||
// InitiateRequest fetches information on the OAuth2 request.
|
// InitiateRequest fetches information on the OAuth2 request.
|
||||||
func (lrd *LogoutReqDoer) InitiateRequest(challenge string) (*ReqInfo, error) {
|
func (lrd *LogoutReqDoer) InitiateRequest(challenge string) (*ReqInfo, error) {
|
||||||
ri, err := initiateRequest(logout, lrd.hydraURL, lrd.fakeTlsTermination, challenge)
|
ri, err := initiateRequest(logout, lrd.hydraURL, lrd.fakeTLSTermination, challenge)
|
||||||
return ri, errors.Wrap(err, "failed to initiate logout request")
|
return ri, errors.Wrap(err, "failed to initiate logout request")
|
||||||
}
|
}
|
||||||
|
|
||||||
// AcceptLogoutRequest accepts the requested logout process, and returns redirect URI.
|
// AcceptLogoutRequest accepts the requested logout process, and returns redirect URI.
|
||||||
func (lrd *LogoutReqDoer) AcceptLogoutRequest(challenge string) (string, error) {
|
func (lrd *LogoutReqDoer) AcceptLogoutRequest(challenge string) (string, error) {
|
||||||
redirectURI, err := acceptRequest(logout, lrd.hydraURL, lrd.fakeTlsTermination, challenge, nil)
|
redirectURI, err := acceptRequest(logout, lrd.hydraURL, lrd.fakeTLSTermination, challenge, nil)
|
||||||
return redirectURI, errors.Wrap(err, "failed to accept logout request")
|
return redirectURI, errors.Wrap(err, "failed to accept logout request")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue