From b0099d2c1bfa22c9078151481d098c7d125cb07d Mon Sep 17 00:00:00 2001 From: Raphael Simon Date: Wed, 12 Apr 2017 11:07:15 -0700 Subject: [PATCH] Add back app so examples compile out of the box --- app/contexts.go | 11 ++++++ app/controllers.go | 30 +++++++++++++++ app/hrefs.go | 11 ++++++ app/media_types.go | 65 ++++++++++++++++++++++++++++++++ app/security.go | 47 +++++++++++++++++++++++ app/user_types.go | 92 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 256 insertions(+) create mode 100644 app/contexts.go create mode 100644 app/controllers.go create mode 100644 app/hrefs.go create mode 100644 app/media_types.go create mode 100644 app/security.go create mode 100644 app/user_types.go diff --git a/app/contexts.go b/app/contexts.go new file mode 100644 index 0000000..7bd4f33 --- /dev/null +++ b/app/contexts.go @@ -0,0 +1,11 @@ +// unnamed API: Application Contexts +// +// Code generated by goagen v1.1.0, DO NOT EDIT. +// +// Command: +// $ goagen +// --design=github.com/goadesign/oauth2/design +// --out=$(GOPATH)/src/github.com/goadesign/oauth2 +// --version=v1.1.0 + +package app diff --git a/app/controllers.go b/app/controllers.go new file mode 100644 index 0000000..af4aabb --- /dev/null +++ b/app/controllers.go @@ -0,0 +1,30 @@ +// unnamed API: Application Controllers +// +// Code generated by goagen v1.1.0, DO NOT EDIT. +// +// Command: +// $ goagen +// --design=github.com/goadesign/oauth2/design +// --out=$(GOPATH)/src/github.com/goadesign/oauth2 +// --version=v1.1.0 + +package app + +import ( + "github.com/goadesign/goa" +) + +// initService sets up the service encoders, decoders and mux. +func initService(service *goa.Service) { + // Setup encoders and decoders + service.Encoder.Register(goa.NewJSONEncoder, "application/json") + service.Encoder.Register(goa.NewGobEncoder, "application/gob", "application/x-gob") + service.Encoder.Register(goa.NewXMLEncoder, "application/xml") + service.Decoder.Register(goa.NewJSONDecoder, "application/json") + service.Decoder.Register(goa.NewGobDecoder, "application/gob", "application/x-gob") + service.Decoder.Register(goa.NewXMLDecoder, "application/xml") + + // Setup default encoder and decoder + service.Encoder.Register(goa.NewJSONEncoder, "*/*") + service.Decoder.Register(goa.NewJSONDecoder, "*/*") +} diff --git a/app/hrefs.go b/app/hrefs.go new file mode 100644 index 0000000..812d261 --- /dev/null +++ b/app/hrefs.go @@ -0,0 +1,11 @@ +// unnamed API: Application Resource Href Factories +// +// Code generated by goagen v1.1.0, DO NOT EDIT. +// +// Command: +// $ goagen +// --design=github.com/goadesign/oauth2/design +// --out=$(GOPATH)/src/github.com/goadesign/oauth2 +// --version=v1.1.0 + +package app diff --git a/app/media_types.go b/app/media_types.go new file mode 100644 index 0000000..9677ded --- /dev/null +++ b/app/media_types.go @@ -0,0 +1,65 @@ +// unnamed API: Application Media Types +// +// Code generated by goagen v1.1.0, DO NOT EDIT. +// +// Command: +// $ goagen +// --design=github.com/goadesign/oauth2/design +// --out=$(GOPATH)/src/github.com/goadesign/oauth2 +// --version=v1.1.0 + +package app + +import ( + "github.com/goadesign/goa" +) + +// OAuth2 error response, see https://tools.ietf.org/html/rfc6749#section-5.2 (default view) +// +// Identifier: application/vnd.goa.example.oauth2.error+json; view=default +type OAuth2ErrorMedia struct { + // Error returned by authorization server + Error string `form:"error" json:"error" xml:"error"` + // Human readable ASCII text providing additional information + ErrorDescription *string `form:"error_description,omitempty" json:"error_description,omitempty" xml:"error_description,omitempty"` + // A URI identifying a human-readable web page with information about the error + ErrorURI *string `form:"error_uri,omitempty" json:"error_uri,omitempty" xml:"error_uri,omitempty"` +} + +// Validate validates the OAuth2ErrorMedia media type instance. +func (mt *OAuth2ErrorMedia) Validate() (err error) { + if mt.Error == "" { + err = goa.MergeErrors(err, goa.MissingAttributeError(`response`, "error")) + } + if !(mt.Error == "invalid_request" || mt.Error == "invalid_client" || mt.Error == "invalid_grant" || mt.Error == "unauthorized_client" || mt.Error == "unsupported_grant_type") { + err = goa.MergeErrors(err, goa.InvalidEnumValueError(`response.error`, mt.Error, []interface{}{"invalid_request", "invalid_client", "invalid_grant", "unauthorized_client", "unsupported_grant_type"})) + } + return +} + +// OAuth2 access token request successful response, see https://tools.ietf.org/html/rfc6749#section-5.1 (default view) +// +// Identifier: application/vnd.goa.example.oauth2.token+json; view=default +type TokenMedia struct { + // The access token issued by the authorization server + AccessToken string `form:"access_token" json:"access_token" xml:"access_token"` + // The lifetime in seconds of the access token + ExpiresIn *int `form:"expires_in,omitempty" json:"expires_in,omitempty" xml:"expires_in,omitempty"` + // The refresh token + RefreshToken *string `form:"refresh_token,omitempty" json:"refresh_token,omitempty" xml:"refresh_token,omitempty"` + // The scope of the access token + Scope *string `form:"scope,omitempty" json:"scope,omitempty" xml:"scope,omitempty"` + // The type of the token issued, e.g. "bearer" or "mac" + TokenType string `form:"token_type" json:"token_type" xml:"token_type"` +} + +// Validate validates the TokenMedia media type instance. +func (mt *TokenMedia) Validate() (err error) { + if mt.AccessToken == "" { + err = goa.MergeErrors(err, goa.MissingAttributeError(`response`, "access_token")) + } + if mt.TokenType == "" { + err = goa.MergeErrors(err, goa.MissingAttributeError(`response`, "token_type")) + } + return +} diff --git a/app/security.go b/app/security.go new file mode 100644 index 0000000..a165338 --- /dev/null +++ b/app/security.go @@ -0,0 +1,47 @@ +// unnamed API: Application Security +// +// Code generated by goagen v1.1.0, DO NOT EDIT. +// +// Command: +// $ goagen +// --design=github.com/goadesign/oauth2/design +// --out=$(GOPATH)/src/github.com/goadesign/oauth2 +// --version=v1.1.0 + +package app + +import ( + "context" + "github.com/goadesign/goa" + "net/http" +) + +type ( + // Private type used to store auth handler info in request context + authMiddlewareKey string +) + +// UseOauth2ClientBasicAuthMiddleware mounts the oauth2_client_basic_auth auth middleware onto the service. +func UseOauth2ClientBasicAuthMiddleware(service *goa.Service, middleware goa.Middleware) { + service.Context = context.WithValue(service.Context, authMiddlewareKey("oauth2_client_basic_auth"), middleware) +} + +// NewOauth2ClientBasicAuthSecurity creates a oauth2_client_basic_auth security definition. +func NewOauth2ClientBasicAuthSecurity() *goa.BasicAuthSecurity { + def := goa.BasicAuthSecurity{} + def.Description = "Basic auth used by client to make the requests needed to retrieve and refresh access tokens" + return &def +} + +// handleSecurity creates a handler that runs the auth middleware for the security scheme. +func handleSecurity(schemeName string, h goa.Handler, scopes ...string) goa.Handler { + return func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error { + scheme := ctx.Value(authMiddlewareKey(schemeName)) + am, ok := scheme.(goa.Middleware) + if !ok { + return goa.NoAuthMiddleware(schemeName) + } + ctx = goa.WithRequiredScopes(ctx, scopes) + return am(h)(ctx, rw, req) + } +} diff --git a/app/user_types.go b/app/user_types.go new file mode 100644 index 0000000..94bb492 --- /dev/null +++ b/app/user_types.go @@ -0,0 +1,92 @@ +// unnamed API: Application User Types +// +// Code generated by goagen v1.1.0, DO NOT EDIT. +// +// Command: +// $ goagen +// --design=github.com/goadesign/oauth2/design +// --out=$(GOPATH)/src/github.com/goadesign/oauth2 +// --version=v1.1.0 + +package app + +import ( + "github.com/goadesign/goa" +) + +// Payload sent by client to obtain refresh and access token or to refresh an access token. +// see https://tools.ietf.org/html/rfc6749#section-4.1.3 and https://tools.ietf.org/html/rfc6749#section-6 +type tokenPayload struct { + // The authorization code received from the authorization server, used for initial refresh and access token request + Code *string `form:"code,omitempty" json:"code,omitempty" xml:"code,omitempty"` + // Value MUST be set to "authorization_code" when obtaining initial refresh and access token. + // Value MUST be set to "refresh_token" when refreshing an access token. + GrantType *string `form:"grant_type,omitempty" json:"grant_type,omitempty" xml:"grant_type,omitempty"` + // The redirect_uri parameter specified when making the authorize request to obtain the authorization code, used for initial refresh and access token request + RedirectURI *string `form:"redirect_uri,omitempty" json:"redirect_uri,omitempty" xml:"redirect_uri,omitempty"` + // The refresh token issued to the client, used for refreshing an access token + RefreshToken *string `form:"refresh_token,omitempty" json:"refresh_token,omitempty" xml:"refresh_token,omitempty"` + // The scope of the access request, used for refreshing an access token + Scope *string `form:"scope,omitempty" json:"scope,omitempty" xml:"scope,omitempty"` +} + +// Validate validates the tokenPayload type instance. +func (ut *tokenPayload) Validate() (err error) { + if ut.GrantType == nil { + err = goa.MergeErrors(err, goa.MissingAttributeError(`response`, "grant_type")) + } + if ut.GrantType != nil { + if !(*ut.GrantType == "authorization_code" || *ut.GrantType == "refresh_token") { + err = goa.MergeErrors(err, goa.InvalidEnumValueError(`response.grant_type`, *ut.GrantType, []interface{}{"authorization_code", "refresh_token"})) + } + } + return +} + +// Publicize creates TokenPayload from tokenPayload +func (ut *tokenPayload) Publicize() *TokenPayload { + var pub TokenPayload + if ut.Code != nil { + pub.Code = ut.Code + } + if ut.GrantType != nil { + pub.GrantType = *ut.GrantType + } + if ut.RedirectURI != nil { + pub.RedirectURI = ut.RedirectURI + } + if ut.RefreshToken != nil { + pub.RefreshToken = ut.RefreshToken + } + if ut.Scope != nil { + pub.Scope = ut.Scope + } + return &pub +} + +// Payload sent by client to obtain refresh and access token or to refresh an access token. +// see https://tools.ietf.org/html/rfc6749#section-4.1.3 and https://tools.ietf.org/html/rfc6749#section-6 +type TokenPayload struct { + // The authorization code received from the authorization server, used for initial refresh and access token request + Code *string `form:"code,omitempty" json:"code,omitempty" xml:"code,omitempty"` + // Value MUST be set to "authorization_code" when obtaining initial refresh and access token. + // Value MUST be set to "refresh_token" when refreshing an access token. + GrantType string `form:"grant_type" json:"grant_type" xml:"grant_type"` + // The redirect_uri parameter specified when making the authorize request to obtain the authorization code, used for initial refresh and access token request + RedirectURI *string `form:"redirect_uri,omitempty" json:"redirect_uri,omitempty" xml:"redirect_uri,omitempty"` + // The refresh token issued to the client, used for refreshing an access token + RefreshToken *string `form:"refresh_token,omitempty" json:"refresh_token,omitempty" xml:"refresh_token,omitempty"` + // The scope of the access request, used for refreshing an access token + Scope *string `form:"scope,omitempty" json:"scope,omitempty" xml:"scope,omitempty"` +} + +// Validate validates the TokenPayload type instance. +func (ut *TokenPayload) Validate() (err error) { + if ut.GrantType == "" { + err = goa.MergeErrors(err, goa.MissingAttributeError(`response`, "grant_type")) + } + if !(ut.GrantType == "authorization_code" || ut.GrantType == "refresh_token") { + err = goa.MergeErrors(err, goa.InvalidEnumValueError(`response.grant_type`, ut.GrantType, []interface{}{"authorization_code", "refresh_token"})) + } + return +}