begin parsing

This commit is contained in:
Livio Amstutz 2019-11-21 16:38:51 +01:00
parent 4b2f7c9de4
commit 3d5de74d02
4 changed files with 73 additions and 17 deletions

View file

@ -1,6 +1,9 @@
package oidc package oidc
import ( import (
"errors"
"strings"
"golang.org/x/text/language" "golang.org/x/text/language"
) )
@ -9,10 +12,10 @@ const (
ResponseTypeIDToken = "id_token token" ResponseTypeIDToken = "id_token token"
ResponseTypeIDTokenOnly = "id_token" ResponseTypeIDTokenOnly = "id_token"
DisplayPage = "page" DisplayPage Display = "page"
DisplayPopup = "popup" DisplayPopup Display = "popup"
DisplayTouch = "touch" DisplayTouch Display = "touch"
DisplayWAP = "wap" DisplayWAP Display = "wap"
PromptNone = "none" PromptNone = "none"
PromptLogin = "login" PromptLogin = "login"
@ -20,31 +23,69 @@ const (
PromptSelectAccount = "select_account" PromptSelectAccount = "select_account"
) )
var displayValues = map[string]Display{
"page": DisplayPage,
"popup": DisplayPopup,
"touch": DisplayTouch,
"wap": DisplayWAP,
}
//AuthRequest according to: //AuthRequest according to:
//https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest //https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
// //
type AuthRequest struct { type AuthRequest struct {
Scopes []string `schema:"scope"` Scopes Scopes `schema:"scope"`
ResponseType ResponseType `schema:"response_type"` ResponseType ResponseType `schema:"response_type"`
ClientID string ClientID string `schema:"client_id"`
RedirectURI string //TODO: type RedirectURI string `schema:"redirect_uri"` //TODO: type
State string State string `schema:"state"`
// ResponseMode TODO: ? // ResponseMode TODO: ?
Nonce string Nonce string `schema:"nonce"`
Display Display Display Display `schema:"display"`
Prompt Prompt Prompt Prompt `schema:"prompt"`
MaxAge uint32 MaxAge uint32 `schema:"max_age"`
UILocales []language.Tag UILocales Locales `schema:"ui_locales"`
IDTokenHint string IDTokenHint string `schema:"id_token_hint"`
LoginHint string LoginHint string `schema:"login_hint"`
ACRValues []string ACRValues []string `schema:"acr_values"`
}
type Scopes []string
func (s *Scopes) UnmarshalText(text []byte) error {
scopes := strings.Split(string(text), " ")
*s = Scopes(scopes)
return nil
} }
type ResponseType string type ResponseType string
type Display string type Display string
func (d *Display) UnmarshalText(text []byte) error {
var ok bool
display := string(text)
*d, ok = displayValues[display]
if !ok {
return errors.New("")
}
return nil
}
type Prompt string type Prompt string
type Locales []language.Tag
func (l *Locales) UnmarshalText(text []byte) error {
locales := strings.Split(string(text), " ")
for _, locale := range locales {
tag, err := language.Parse(locale)
if err == nil && !tag.IsRoot() {
*l = append(*l, tag)
}
}
return nil
}

View file

@ -4,11 +4,24 @@ import (
"errors" "errors"
"net/http" "net/http"
"github.com/gorilla/schema"
"github.com/caos/oidc/pkg/oidc" "github.com/caos/oidc/pkg/oidc"
) )
func ParseAuthRequest(w http.ResponseWriter, r *http.Request) (*oidc.AuthRequest, error) { func ParseAuthRequest(w http.ResponseWriter, r *http.Request) (*oidc.AuthRequest, error) {
err := r.ParseForm()
if err != nil {
return nil, errors.New("Unimplemented") //TODO: impl return nil, errors.New("Unimplemented") //TODO: impl
}
authReq := new(oidc.AuthRequest)
//TODO:
d := schema.NewDecoder()
d.IgnoreUnknownKeys(true)
err = d.Decode(authReq, r.Form)
return authReq, err
} }
func ValidateAuthRequest(authRequest *oidc.AuthRequest) error { func ValidateAuthRequest(authRequest *oidc.AuthRequest) error {

View file

@ -14,5 +14,6 @@ require (
github.com/caos/oidc/pkg/utils v0.0.0-00010101000000-000000000000 github.com/caos/oidc/pkg/utils v0.0.0-00010101000000-000000000000
github.com/caos/utils/logging v0.0.0-20191104132131-b318678afbef github.com/caos/utils/logging v0.0.0-20191104132131-b318678afbef
github.com/gorilla/mux v1.7.3 github.com/gorilla/mux v1.7.3
github.com/gorilla/schema v1.1.0
github.com/stretchr/testify v1.4.0 github.com/stretchr/testify v1.4.0
) )

1
pkg/utils/formParser.go Normal file
View file

@ -0,0 +1 @@
package utils