fixes of conf testing

This commit is contained in:
Livio Amstutz 2019-12-06 15:58:20 +01:00
parent 310220d38e
commit 2b36498365
3 changed files with 26 additions and 7 deletions

View file

@ -34,6 +34,8 @@ type AuthRequest struct {
ID string ID string
ResponseType oidc.ResponseType ResponseType oidc.ResponseType
RedirectURI string RedirectURI string
Nonce string
ClientID string
} }
func (a *AuthRequest) GetACR() string { func (a *AuthRequest) GetACR() string {
@ -48,7 +50,7 @@ func (a *AuthRequest) GetAMR() []string {
func (a *AuthRequest) GetAudience() []string { func (a *AuthRequest) GetAudience() []string {
return []string{ return []string{
a.ID, a.ClientID,
} }
} }
@ -57,7 +59,7 @@ func (a *AuthRequest) GetAuthTime() time.Time {
} }
func (a *AuthRequest) GetClientID() string { func (a *AuthRequest) GetClientID() string {
return a.ID return a.ClientID
} }
func (a *AuthRequest) GetCode() string { func (a *AuthRequest) GetCode() string {
@ -69,11 +71,12 @@ func (a *AuthRequest) GetID() string {
} }
func (a *AuthRequest) GetNonce() string { func (a *AuthRequest) GetNonce() string {
return "nonce" return a.Nonce
} }
func (a *AuthRequest) GetRedirectURI() string { func (a *AuthRequest) GetRedirectURI() string {
return "http://localhost:5556/auth/callback" return "https://op.certification.openid.net:62054/authz_cb"
// return "http://localhost:5556/auth/callback"
} }
func (a *AuthRequest) GetResponseType() oidc.ResponseType { func (a *AuthRequest) GetResponseType() oidc.ResponseType {
@ -96,8 +99,13 @@ func (a *AuthRequest) GetSubject() string {
return "sub" return "sub"
} }
var (
a = &AuthRequest{}
)
func (s *AuthStorage) CreateAuthRequest(authReq *oidc.AuthRequest) (op.AuthRequest, error) { func (s *AuthStorage) CreateAuthRequest(authReq *oidc.AuthRequest) (op.AuthRequest, error) {
return &AuthRequest{ID: "id"}, nil a = &AuthRequest{ID: "id", ClientID: authReq.ClientID, ResponseType: authReq.ResponseType, Nonce: authReq.Nonce}
return a, nil
} }
func (s *OPStorage) GetClientByClientID(id string) (op.Client, error) { func (s *OPStorage) GetClientByClientID(id string) (op.Client, error) {
if id == "none" { if id == "none" {
@ -114,7 +122,7 @@ func (s *OPStorage) GetClientByClientID(id string) (op.Client, error) {
return &ConfClient{applicationType: appType}, nil return &ConfClient{applicationType: appType}, nil
} }
func (s *AuthStorage) AuthRequestByCode(op.Client, string, string) (op.AuthRequest, error) { func (s *AuthStorage) AuthRequestByCode(op.Client, string, string) (op.AuthRequest, error) {
return &AuthRequest{ID: "native"}, nil return a, nil
} }
func (s *OPStorage) AuthorizeClientIDSecret(string, string) (op.Client, error) { func (s *OPStorage) AuthorizeClientIDSecret(string, string) (op.Client, error) {
return &ConfClient{}, nil return &ConfClient{}, nil

View file

@ -79,6 +79,9 @@ func ValidateAuthRequest(authReq *oidc.AuthRequest, storage Storage) error {
if err := ValidateAuthReqRedirectURI(authReq.RedirectURI, authReq.ClientID, authReq.ResponseType, storage); err != nil { if err := ValidateAuthReqRedirectURI(authReq.RedirectURI, authReq.ClientID, authReq.ResponseType, storage); err != nil {
return err return err
} }
if err := ValidateAuthReqResponseType(authReq.ResponseType); err != nil {
return err
}
return nil return nil
// return errors.New("Unimplemented") //TODO: impl https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.3.1.2.2 // return errors.New("Unimplemented") //TODO: impl https://openid.net/specs/openid-connect-core-1_0.html#rfc.section.3.1.2.2
@ -133,6 +136,13 @@ func ValidateAuthReqRedirectURI(uri, client_id string, responseType oidc.Respons
return nil return nil
} }
func ValidateAuthReqResponseType(responseType oidc.ResponseType) error {
if responseType == "" {
return ErrInvalidRequest("response_type empty")
}
return nil
}
func RedirectToLogin(authReqID string, client Client, w http.ResponseWriter, r *http.Request) { func RedirectToLogin(authReqID string, client Client, w http.ResponseWriter, r *http.Request) {
login := client.LoginURL(authReqID) login := client.LoginURL(authReqID)
http.Redirect(w, r, login, http.StatusFound) http.Redirect(w, r, login, http.StatusFound)

View file

@ -60,7 +60,8 @@ func AuthRequestError(w http.ResponseWriter, r *http.Request, authReq ErrAuthReq
return return
} }
url := authReq.GetRedirectURI() url := authReq.GetRedirectURI()
if authReq.GetResponseType() == oidc.ResponseTypeCode { responseType := authReq.GetResponseType()
if responseType == "" || responseType == oidc.ResponseTypeCode {
url += "?" + params url += "?" + params
} else { } else {
url += "#" + params url += "#" + params