Skip to content

Commit

Permalink
oauth2: improve swagger definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas authored and arekkas committed Oct 5, 2017
1 parent 94bd5bd commit 0c05da3
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 104 deletions.
129 changes: 48 additions & 81 deletions docs/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -884,28 +884,17 @@
"consent"
],
"summary": "Receive consent request information",
"operationId": "getConsentRequest",
"operationId": "getOAuth2ConsentRequest",
"security": [
{
"oauth2": [
"hydra.consent"
]
}
],
"parameters": [
{
"uniqueItems": true,
"type": "string",
"x-go-name": "ID",
"description": "The id of the OAuth 2.0 Consent Request.",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"$ref": "#/responses/oauthConsentRequest"
"$ref": "#/responses/oAuth2ConsentRequest"
},
"401": {
"$ref": "#/responses/genericError"
Expand Down Expand Up @@ -934,7 +923,7 @@
"consent"
],
"summary": "Accept a consent request",
"operationId": "acceptConsentRequest",
"operationId": "acceptOAuth2ConsentRequest",
"security": [
{
"oauth2": [
Expand All @@ -950,15 +939,6 @@
"schema": {
"$ref": "#/definitions/acceptConsentRequestPayload"
}
},
{
"uniqueItems": true,
"type": "string",
"x-go-name": "ID",
"description": "The id of the OAuth 2.0 Consent Request.",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
Expand Down Expand Up @@ -992,7 +972,7 @@
"consent"
],
"summary": "Reject a consent request",
"operationId": "rejectConsentRequest",
"operationId": "rejectOAuth2ConsentRequest",
"security": [
{
"oauth2": [
Expand All @@ -1008,15 +988,6 @@
"schema": {
"$ref": "#/definitions/rejectConsentRequestPayload"
}
},
{
"uniqueItems": true,
"type": "string",
"x-go-name": "ID",
"description": "The id of the OAuth 2.0 Consent Request.",
"name": "id",
"in": "path",
"required": true
}
],
"responses": {
Expand Down Expand Up @@ -1049,15 +1020,15 @@
"oauth2"
],
"summary": "Introspect an OAuth2 access token",
"operationId": "introspectOAuthToken",
"operationId": "introspectToken",
"security": [
{
"oauth2": []
}
],
"responses": {
"200": {
"$ref": "#/responses/introspectOAuthTokenResponse"
"$ref": "#/responses/introspectOAuth2TokenResponse"
},
"401": {
"$ref": "#/responses/genericError"
Expand Down Expand Up @@ -1085,7 +1056,7 @@
"oauth2"
],
"summary": "Revoke an OAuth2 access token",
"operationId": "revokeOAuthToken",
"operationId": "revokeOAuth2Token",
"security": [
{
"oauth2": []
Expand All @@ -1099,13 +1070,9 @@
"schema": {
"type": "object",
"properties": {
"access_token": {
"type": "string",
"x-go-name": "AccessToken"
},
"refresh_token": {
"token": {
"type": "string",
"x-go-name": "RefreshToken"
"x-go-name": "Token"
}
}
}
Expand Down Expand Up @@ -2159,41 +2126,6 @@
"x-go-name": "AccessRequest",
"x-go-package": "github.com/ory/hydra/firewall"
},
"consentRequest": {
"type": "object",
"title": "ConsentRequest represents a consent request.",
"properties": {
"audience": {
"description": "Audience is the client id that initiated the OAuth2 request.",
"type": "string",
"x-go-name": "Audience"
},
"expiresAt": {
"description": "ExpiresAt is the time where the access request will expire.",
"x-go-name": "ExpiresAt"
},
"id": {
"description": "ID is the id of this consent request.",
"type": "string",
"x-go-name": "ID"
},
"redirectUrl": {
"description": "Redirect URL is the URL where the user agent should be redirected to after the consent has been\naccepted or rejected.",
"type": "string",
"x-go-name": "RedirectURL"
},
"requestedScopes": {
"description": "RequestedScopes represents a list of scopes that have been requested by the OAuth2 request initiator.",
"type": "array",
"items": {
"type": "string"
},
"x-go-name": "RequestedScopes"
}
},
"x-go-name": "ConsentRequest",
"x-go-package": "github.com/ory/hydra/oauth2"
},
"createJsonWebKeySetPayload": {
"type": "object",
"required": [
Expand Down Expand Up @@ -2453,6 +2385,41 @@
"x-go-name": "Client",
"x-go-package": "github.com/ory/hydra/client"
},
"oAuth2consentRequest": {
"type": "object",
"title": "ConsentRequest represents a consent request.",
"properties": {
"audience": {
"description": "Audience is the client id that initiated the OAuth2 request.",
"type": "string",
"x-go-name": "Audience"
},
"expiresAt": {
"description": "ExpiresAt is the time where the access request will expire.",
"x-go-name": "ExpiresAt"
},
"id": {
"description": "ID is the id of this consent request.",
"type": "string",
"x-go-name": "ID"
},
"redirectUrl": {
"description": "Redirect URL is the URL where the user agent should be redirected to after the consent has been\naccepted or rejected.",
"type": "string",
"x-go-name": "RedirectURL"
},
"requestedScopes": {
"description": "RequestedScopes represents a list of scopes that have been requested by the OAuth2 request initiator.",
"type": "array",
"items": {
"type": "string"
},
"x-go-name": "RequestedScopes"
}
},
"x-go-name": "ConsentRequest",
"x-go-package": "github.com/ory/hydra/oauth2"
},
"policy": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -2912,13 +2879,13 @@
}
}
},
"introspectOAuthTokenResponse": {
"introspectOAuth2TokenResponse": {
"description": "The token introspection response",
"schema": {
"type": "object",
"properties": {
"active": {
"description": "Boolean indicator of whether or not the presented token\nis currently active. The specifics of a token's \"active\" state\nwill vary depending on the implementation of the authorization\nserver and the information it keeps about its tokens, but a \"true\"\nvalue return for the \"active\" property will generally indicate\nthat a given token has been issued by this authorization server,\nhas not been revoked by the resource owner, and is within its\ngiven time window of validity (e.g., after its issuance time and\nbefore its expiration time).",
"description": "Boolean indicator of whether or not the presented token\nis currently active. An active token is neither refreshed nor revoked.",
"type": "boolean",
"x-go-name": "Active"
},
Expand Down Expand Up @@ -2975,10 +2942,10 @@
}
}
},
"oauthConsentRequest": {
"oAuth2ConsentRequest": {
"description": "The consent request response",
"schema": {
"$ref": "#/definitions/consentRequest"
"$ref": "#/definitions/oAuth2consentRequest"
}
},
"oauthTokenResponse": {
Expand Down
8 changes: 4 additions & 4 deletions oauth2/consent_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (h *ConsentSessionHandler) SetRoutes(r *httprouter.Router) {
r.PATCH(ConsentRequestPath+"/:id/accept", h.AcceptConsentRequestHandler)
}

// swagger:route GET /oauth2/consent/requests/{id} oauth2 consent getConsentRequest
// swagger:route GET /oauth2/consent/requests/{id} oauth2 consent getOAuth2ConsentRequest
//
// Receive consent request information
//
Expand Down Expand Up @@ -61,7 +61,7 @@ func (h *ConsentSessionHandler) SetRoutes(r *httprouter.Router) {
// oauth2: hydra.consent
//
// Responses:
// 200: oauthConsentRequest
// 200: oAuth2ConsentRequest
// 401: genericError
// 500: genericError
func (h *ConsentSessionHandler) FetchConsentRequest(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
Expand All @@ -81,7 +81,7 @@ func (h *ConsentSessionHandler) FetchConsentRequest(w http.ResponseWriter, r *ht
}
}

// swagger:route PATCH /oauth2/consent/requests/{id}/reject oauth2 consent rejectConsentRequest
// swagger:route PATCH /oauth2/consent/requests/{id}/reject oauth2 consent rejectOAuth2ConsentRequest
//
// Reject a consent request
//
Expand Down Expand Up @@ -136,7 +136,7 @@ func (h *ConsentSessionHandler) RejectConsentRequestHandler(w http.ResponseWrite
w.WriteHeader(http.StatusNoContent)
}

// swagger:route PATCH /oauth2/consent/requests/{id}/accept oauth2 consent acceptConsentRequest
// swagger:route PATCH /oauth2/consent/requests/{id}/accept oauth2 consent acceptOAuth2ConsentRequest
//
// Accept a consent request
//
Expand Down
2 changes: 1 addition & 1 deletion oauth2/consent_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import "time"

// ConsentRequest represents a consent request.
//
// swagger:model consentRequest
// swagger:model oAuth2consentRequest
type ConsentRequest struct {
// ID is the id of this consent request.
ID string `json:"id"`
Expand Down
39 changes: 25 additions & 14 deletions oauth2/doc.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package oauth2

// swagger:parameters revokeOAuthToken
type swaggerCreateClientPayload struct {
// swagger:parameters revokeOAuth2Token
type swaggerRevokeOAuth2TokenParameters struct {
// in: body
// required: true
Body struct {
Expand All @@ -10,22 +10,22 @@ type swaggerCreateClientPayload struct {
}
}

// swagger:parameters rejectConsentRequest
// swagger:parameters rejectOAuth2ConsentRequest
type swaggerRejectConsentRequest struct {
// in: body
// required: true
Body RejectConsentRequestPayload
}

// swagger:parameters acceptConsentRequest
// swagger:parameters acceptOAuth2ConsentRequest
type swaggerAcceptConsentRequest struct {
// in: body
// required: true
Body AcceptConsentRequestPayload
}

// The consent request response
// swagger:response oauthConsentRequest
// swagger:response oAuth2ConsentRequest
type swaggerOAuthConsentRequest struct {
// in: body
Body ConsentRequest
Expand Down Expand Up @@ -60,19 +60,12 @@ type swaggerOAuthTokenResponse struct {
}

// The token introspection response
// swagger:response introspectOAuthTokenResponse
// swagger:response introspectOAuth2TokenResponse
type swaggerOAuthIntrospectionResponse struct {
// in: body
Body struct {
// Boolean indicator of whether or not the presented token
// is currently active. The specifics of a token's "active" state
// will vary depending on the implementation of the authorization
// server and the information it keeps about its tokens, but a "true"
// value return for the "active" property will generally indicate
// that a given token has been issued by this authorization server,
// has not been revoked by the resource owner, and is within its
// given time window of validity (e.g., after its issuance time and
// before its expiration time).
// is currently active. An active token is neither refreshed nor revoked.
Active bool `json:"active"`

// Client identifier for the OAuth 2.0 client that
Expand All @@ -86,6 +79,7 @@ type swaggerOAuthIntrospectionResponse struct {
// Integer timestamp, measured in the number of seconds
// since January 1 1970 UTC, indicating when this token will expire
ExpiresAt int64 `json:"exp,omitempty"`

// Integer timestamp, measured in the number of seconds
// since January 1 1970 UTC, indicating when this token was
//originally issued
Expand All @@ -105,6 +99,23 @@ type swaggerOAuthIntrospectionResponse struct {
}
}

// swagger:parameters introspectOAuth2Token
type swaggerOAuthIntrospectionRequest struct {
// in: body
Body struct {
// required: true
// The string value of the token. For access tokens, this
// is the "access_token" value returned from the token endpoint
// defined in OAuth 2.0 [RFC6749], Section 5.1.
// This endpoint DOES NOT accept refresh tokens for validation.
Token string `json:"token"`

// An optional, space separated list of required scopes. If the access token was not granted one of the
// scopes, the result of active will be false.
Scope string `json:"scope"`
}
}

// swagger:parameters getConsentRequest acceptConsentRequest rejectConsentRequest
type swaggerOAuthConsentRequestPayload struct {
// The id of the OAuth 2.0 Consent Request.
Expand Down
6 changes: 3 additions & 3 deletions oauth2/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (h *Handler) WellKnownHandler(w http.ResponseWriter, r *http.Request, _ htt
h.H.Write(w, r, wellKnown)
}

// swagger:route POST /oauth2/revoke oauth2 revokeOAuthToken
// swagger:route POST /oauth2/revoke oauth2 revokeOAuth2Token
//
// Revoke an OAuth2 access token
//
Expand Down Expand Up @@ -158,7 +158,7 @@ func (h *Handler) RevocationHandler(w http.ResponseWriter, r *http.Request, _ ht
h.OAuth2.WriteRevocationResponse(w, err)
}

// swagger:route POST /oauth2/introspect oauth2 introspectOAuthToken
// swagger:route POST /oauth2/introspect oauth2 introspectToken
//
// Introspect an OAuth2 access token
//
Expand All @@ -176,7 +176,7 @@ func (h *Handler) RevocationHandler(w http.ResponseWriter, r *http.Request, _ ht
// oauth2:
//
// Responses:
// 200: introspectOAuthTokenResponse
// 200: introspectOAuth2TokenResponse
// 401: genericError
// 500: genericError
func (h *Handler) IntrospectHandler(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
Expand Down
Loading

0 comments on commit 0c05da3

Please sign in to comment.