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
import (
"errors"
"strings"
"golang.org/x/text/language"
)
@ -9,10 +12,10 @@ const (
ResponseTypeIDToken = "id_token token"
ResponseTypeIDTokenOnly = "id_token"
DisplayPage = "page"
DisplayPopup = "popup"
DisplayTouch = "touch"
DisplayWAP = "wap"
DisplayPage Display = "page"
DisplayPopup Display = "popup"
DisplayTouch Display = "touch"
DisplayWAP Display = "wap"
PromptNone = "none"
PromptLogin = "login"
@ -20,31 +23,69 @@ const (
PromptSelectAccount = "select_account"
)
var displayValues = map[string]Display{
"page": DisplayPage,
"popup": DisplayPopup,
"touch": DisplayTouch,
"wap": DisplayWAP,
}
//AuthRequest according to:
//https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest
//
type AuthRequest struct {
Scopes []string `schema:"scope"`
Scopes Scopes `schema:"scope"`
ResponseType ResponseType `schema:"response_type"`
ClientID string
RedirectURI string //TODO: type
ClientID string `schema:"client_id"`
RedirectURI string `schema:"redirect_uri"` //TODO: type
State string
State string `schema:"state"`
// ResponseMode TODO: ?
Nonce string
Display Display
Prompt Prompt
MaxAge uint32
UILocales []language.Tag
IDTokenHint string
LoginHint string
ACRValues []string
Nonce string `schema:"nonce"`
Display Display `schema:"display"`
Prompt Prompt `schema:"prompt"`
MaxAge uint32 `schema:"max_age"`
UILocales Locales `schema:"ui_locales"`
IDTokenHint string `schema:"id_token_hint"`
LoginHint string `schema:"login_hint"`
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 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 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
}