schema: generate code

This commit is contained in:
Bobby Rullo 2016-04-15 17:23:27 -07:00
parent 1bbca1d43c
commit 35cefb7da9
4 changed files with 112 additions and 86 deletions

View file

@ -20,32 +20,41 @@ __Version:__ v1
} }
``` ```
### Client
```
{
clientName: string // OPTIONAL. Name of the Client to be presented to the End-User. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) .,
clientURI: string // OPTIONAL. URL of the home page of the Client. The value of this field MUST point to a valid Web page. If present, the server SHOULD display this URL to the End-User in a followable fashion. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) .,
id: string // The client ID. Ignored in client create requests.,
isAdmin: boolean,
logoURI: string // OPTIONAL. URL that references a logo for the Client application. If present, the server SHOULD display this image to the End-User during approval. The value of this field MUST point to a valid image file. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) .,
redirectURIs: [
string
],
secret: string
}
```
### ClientCreateRequest ### ClientCreateRequest
A request to register a client with dex. A request to register a client with dex.
``` ```
{ {
client: { client: Client
client_name: string // OPTIONAL. Name of the Client to be presented to the End-User. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) .,
client_uri: string // OPTIONAL. URL of the home page of the Client. The value of this field MUST point to a valid Web page. If present, the server SHOULD display this URL to the End-User in a followable fashion. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) .,
logo_uri: string // OPTIONAL. URL that references a logo for the Client application. If present, the server SHOULD display this image to the End-User during approval. The value of this field MUST point to a valid image file. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) .,
redirect_uris: [
string
]
},
isAdmin: boolean
} }
``` ```
### ClientRegistrationResponse ### ClientCreateResponse
Upon successful registration, an ID and secret is assigned to the client. Upon successful registration, an ID and secret is assigned to the client.
``` ```
{ {
client_id: string, client: Client
client_secret: string
} }
``` ```
@ -137,7 +146,7 @@ Upon successful registration, an ID and secret is assigned to the client.
> |Code|Description|Type| > |Code|Description|Type|
|:-----|:-----|:-----| |:-----|:-----|:-----|
| 200 | | [ClientRegistrationResponse](#clientregistrationresponse) | | 200 | | [ClientCreateResponse](#clientcreateresponse) |
| default | Unexpected error | | | default | Unexpected error | |

View file

@ -97,49 +97,52 @@ type Admin struct {
Password string `json:"password,omitempty"` Password string `json:"password,omitempty"`
} }
type ClientCreateRequest struct { type Client struct {
Client *ClientCreateRequestClient `json:"client,omitempty"` // ClientName: OPTIONAL. Name of the Client to be presented to the
IsAdmin bool `json:"isAdmin,omitempty"`
}
type ClientCreateRequestClient struct {
// Client_name: OPTIONAL. Name of the Client to be presented to the
// End-User. If desired, representation of this Claim in different // End-User. If desired, representation of this Claim in different
// languages and scripts is represented as described in Section 2.1 ( // languages and scripts is represented as described in Section 2.1 (
// Metadata Languages and Scripts ) . // Metadata Languages and Scripts ) .
Client_name string `json:"client_name,omitempty"` ClientName string `json:"clientName,omitempty"`
// Client_uri: OPTIONAL. URL of the home page of the Client. The value // ClientURI: OPTIONAL. URL of the home page of the Client. The value of
// of this field MUST point to a valid Web page. If present, the server // this field MUST point to a valid Web page. If present, the server
// SHOULD display this URL to the End-User in a followable fashion. If // SHOULD display this URL to the End-User in a followable fashion. If
// desired, representation of this Claim in different languages and // desired, representation of this Claim in different languages and
// scripts is represented as described in Section 2.1 ( Metadata // scripts is represented as described in Section 2.1 ( Metadata
// Languages and Scripts ) . // Languages and Scripts ) .
Client_uri string `json:"client_uri,omitempty"` ClientURI string `json:"clientURI,omitempty"`
// Logo_uri: OPTIONAL. URL that references a logo for the Client // Id: The client ID. Ignored in client create requests.
Id string `json:"id,omitempty"`
IsAdmin bool `json:"isAdmin,omitempty"`
// LogoURI: OPTIONAL. URL that references a logo for the Client
// application. If present, the server SHOULD display this image to the // application. If present, the server SHOULD display this image to the
// End-User during approval. The value of this field MUST point to a // End-User during approval. The value of this field MUST point to a
// valid image file. If desired, representation of this Claim in // valid image file. If desired, representation of this Claim in
// different languages and scripts is represented as described in // different languages and scripts is represented as described in
// Section 2.1 ( Metadata Languages and Scripts ) . // Section 2.1 ( Metadata Languages and Scripts ) .
Logo_uri string `json:"logo_uri,omitempty"` LogoURI string `json:"logoURI,omitempty"`
// Redirect_uris: REQUIRED. Array of Redirection URI values used by the // RedirectURIs: REQUIRED. Array of Redirection URI values used by the
// Client. One of these registered Redirection URI values MUST exactly // Client. One of these registered Redirection URI values MUST exactly
// match the redirect_uri parameter value used in each Authorization // match the redirect_uri parameter value used in each Authorization
// Request, with the matching performed as described in Section 6.2.1 of // Request, with the matching performed as described in Section 6.2.1 of
// [RFC3986] ( Berners-Lee, T., Fielding, R., and L. Masinter, // [RFC3986] ( Berners-Lee, T., Fielding, R., and L. Masinter,
// “Uniform Resource Identifier (URI): Generic Syntax,” January // “Uniform Resource Identifier (URI): Generic Syntax,” January
// 2005. ) (Simple String Comparison). // 2005. ) (Simple String Comparison).
Redirect_uris []string `json:"redirect_uris,omitempty"` RedirectURIs []string `json:"redirectURIs,omitempty"`
Secret string `json:"secret,omitempty"`
} }
type ClientRegistrationResponse struct { type ClientCreateRequest struct {
Client_id string `json:"client_id,omitempty"` Client *Client `json:"client,omitempty"`
}
Client_secret string `json:"client_secret,omitempty"` type ClientCreateResponse struct {
Client *Client `json:"client,omitempty"`
} }
type State struct { type State struct {
@ -310,7 +313,7 @@ func (c *ClientCreateCall) Fields(s ...googleapi.Field) *ClientCreateCall {
return c return c
} }
func (c *ClientCreateCall) Do() (*ClientRegistrationResponse, error) { func (c *ClientCreateCall) Do() (*ClientCreateResponse, error) {
var body io.Reader = nil var body io.Reader = nil
body, err := googleapi.WithoutDataWrapper.JSONReader(c.clientcreaterequest) body, err := googleapi.WithoutDataWrapper.JSONReader(c.clientcreaterequest)
if err != nil { if err != nil {
@ -336,7 +339,7 @@ func (c *ClientCreateCall) Do() (*ClientRegistrationResponse, error) {
if err := googleapi.CheckResponse(res); err != nil { if err := googleapi.CheckResponse(res); err != nil {
return nil, err return nil, err
} }
var ret *ClientRegistrationResponse var ret *ClientCreateResponse
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil { if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
return nil, err return nil, err
} }
@ -350,7 +353,7 @@ func (c *ClientCreateCall) Do() (*ClientRegistrationResponse, error) {
// "$ref": "ClientCreateRequest" // "$ref": "ClientCreateRequest"
// }, // },
// "response": { // "response": {
// "$ref": "ClientRegistrationResponse" // "$ref": "ClientCreateResponse"
// } // }
// } // }

View file

@ -51,53 +51,66 @@ const DiscoveryJSON = `{
} }
} }
}, },
"ClientCreateRequest": { "Client": {
"id": "ClientCreateRequest", "id": "Client",
"type": "object", "type": "object",
"description": "A request to register a client with dex.", "properties": {
"properties": { "id": {
"isAdmin": { "type": "string",
"type": "boolean" "description": "The client ID. Ignored in client create requests."
}, },
"client": { "secret": {
"type": "object", "type": "string",
"properties": { "description": "The client secret. Ignored in client create requests."
"redirect_uris": { },
"type": "array", "secret": {
"items": { "type": "string",
"type": "string" "format": "byte"
}, },
"description": "REQUIRED. Array of Redirection URI values used by the Client. One of these registered Redirection URI values MUST exactly match the redirect_uri parameter value used in each Authorization Request, with the matching performed as described in Section 6.2.1 of [RFC3986] ( Berners-Lee, T., Fielding, R., and L. Masinter, “Uniform Resource Identifier (URI): Generic Syntax,” January 2005. ) (Simple String Comparison)." "isAdmin": {
}, "type": "boolean"
"client_name": { },
"type": "string", "redirectURIs": {
"description": "OPTIONAL. Name of the Client to be presented to the End-User. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ." "type": "array",
}, "items": {
"logo_uri": { "type": "string"
"type": "string", },
"description": "OPTIONAL. URL that references a logo for the Client application. If present, the server SHOULD display this image to the End-User during approval. The value of this field MUST point to a valid image file. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ." "description": "REQUIRED. Array of Redirection URI values used by the Client. One of these registered Redirection URI values MUST exactly match the redirect_uri parameter value used in each Authorization Request, with the matching performed as described in Section 6.2.1 of [RFC3986] ( Berners-Lee, T., Fielding, R., and L. Masinter, “Uniform Resource Identifier (URI): Generic Syntax,” January 2005. ) (Simple String Comparison)."
}, },
"client_uri": { "clientName": {
"type": "string", "type": "string",
"description": "OPTIONAL. URL of the home page of the Client. The value of this field MUST point to a valid Web page. If present, the server SHOULD display this URL to the End-User in a followable fashion. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ." "description": "OPTIONAL. Name of the Client to be presented to the End-User. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ."
} },
} "logoURI": {
} "type": "string",
"description": "OPTIONAL. URL that references a logo for the Client application. If present, the server SHOULD display this image to the End-User during approval. The value of this field MUST point to a valid image file. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ."
},
"clientURI": {
"type": "string",
"description": "OPTIONAL. URL of the home page of the Client. The value of this field MUST point to a valid Web page. If present, the server SHOULD display this URL to the End-User in a followable fashion. If desired, representation of this Claim in different languages and scripts is represented as described in Section 2.1 ( Metadata Languages and Scripts ) ."
} }
}
}, },
"ClientRegistrationResponse": { "ClientCreateRequest": {
"id": "ClientRegistrationResponse", "id": "ClientCreateRequest",
"type": "object", "type": "object",
"description": "Upon successful registration, an ID and secret is assigned to the client.", "description": "A request to register a client with dex.",
"properties": { "properties": {
"client_id": { "client": {
"type": "string" "$ref": "Client"
}, }
"client_secret": {
"type": "string"
}
}
} }
},
"ClientCreateResponse": {
"id": "ClientCreateResponse",
"type": "object",
"description": "Upon successful registration, an ID and secret is assigned to the client.",
"properties": {
"client":{
"$ref": "Client"
}
}
}
}, },
"resources": { "resources": {
"Admin": { "Admin": {
@ -160,7 +173,7 @@ const DiscoveryJSON = `{
"$ref": "ClientCreateRequest" "$ref": "ClientCreateRequest"
}, },
"response": { "response": {
"$ref": "ClientRegistrationResponse" "$ref": "ClientCreateResponse"
} }
} }
} }

View file

@ -4,11 +4,12 @@ import (
"errors" "errors"
"net/url" "net/url"
"github.com/coreos/dex/client"
"github.com/coreos/go-oidc/oidc" "github.com/coreos/go-oidc/oidc"
) )
func MapSchemaClientToClientIdentity(sc Client) (oidc.ClientIdentity, error) { func MapSchemaClientToClient(sc Client) (client.Client, error) {
ci := oidc.ClientIdentity{ ci := client.Client{
Credentials: oidc.ClientCredentials{ Credentials: oidc.ClientCredentials{
ID: sc.Id, ID: sc.Id,
}, },
@ -19,12 +20,12 @@ func MapSchemaClientToClientIdentity(sc Client) (oidc.ClientIdentity, error) {
for i, ru := range sc.RedirectURIs { for i, ru := range sc.RedirectURIs {
if ru == "" { if ru == "" {
return oidc.ClientIdentity{}, errors.New("redirect URL empty") return client.Client{}, errors.New("redirect URL empty")
} }
u, err := url.Parse(ru) u, err := url.Parse(ru)
if err != nil { if err != nil {
return oidc.ClientIdentity{}, errors.New("redirect URL invalid") return client.Client{}, errors.New("redirect URL invalid")
} }
ci.Metadata.RedirectURIs[i] = *u ci.Metadata.RedirectURIs[i] = *u
@ -33,7 +34,7 @@ func MapSchemaClientToClientIdentity(sc Client) (oidc.ClientIdentity, error) {
return ci, nil return ci, nil
} }
func MapClientIdentityToSchemaClient(c oidc.ClientIdentity) Client { func MapClientToSchemaClient(c client.Client) Client {
cl := Client{ cl := Client{
Id: c.Credentials.ID, Id: c.Credentials.ID,
RedirectURIs: make([]string, len(c.Metadata.RedirectURIs)), RedirectURIs: make([]string, len(c.Metadata.RedirectURIs)),
@ -44,7 +45,7 @@ func MapClientIdentityToSchemaClient(c oidc.ClientIdentity) Client {
return cl return cl
} }
func MapClientIdentityToSchemaClientWithSecret(c oidc.ClientIdentity) ClientWithSecret { func MapClientToSchemaClientWithSecret(c client.Client) ClientWithSecret {
cl := ClientWithSecret{ cl := ClientWithSecret{
Id: c.Credentials.ID, Id: c.Credentials.ID,
Secret: c.Credentials.Secret, Secret: c.Credentials.Secret,