Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cookie as an option for oauth2_introspection authenticator #301

Merged
merged 2 commits into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .schemas/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@
"header": {
"title": "Header",
"type": "string",
"description": "The header (case insensitive) that must contain a token for request authentication.\n It can't be set along with query_parameter."
"description": "The header (case insensitive) that must contain a token for request authentication.\n It can't be set along with query_parameter or cookie."
}
}
},
Expand All @@ -493,7 +493,19 @@
"query_parameter": {
"title": "Query Parameter",
"type": "string",
"description": "The query parameter (case sensitive) that must contain a token for request authentication.\n It can't be set along with header."
"description": "The query parameter (case sensitive) that must contain a token for request authentication.\n It can't be set along with header or cookie."
}
}
},
{
"required": [
"cookie"
],
"properties": {
"cookie": {
"title": "Cookie",
"type": "string",
"description": "The cookie (case sensitive) that must contain a token for request authentication.\n It can't be set along with header or query_parameter."
}
}
}
Expand Down Expand Up @@ -1242,4 +1254,4 @@
},
"required": [],
"additionalProperties": false
}
}
7 changes: 7 additions & 0 deletions helper/bearer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
type BearerTokenLocation struct {
Header *string `json:"header"`
QueryParameter *string `json:"query_parameter"`
Cookie *string `json:"cookie"`
}

func BearerTokenFromRequest(r *http.Request, tokenLocation *BearerTokenLocation) string {
Expand All @@ -40,6 +41,12 @@ func BearerTokenFromRequest(r *http.Request, tokenLocation *BearerTokenLocation)
return r.Header.Get(*tokenLocation.Header)
} else if tokenLocation.QueryParameter != nil {
return r.FormValue(*tokenLocation.QueryParameter)
} else if tokenLocation.Cookie != nil {
cookie, err := r.Cookie(*tokenLocation.Cookie)
if err != nil {
return ""
}
return cookie.Value
}
}
token := r.Header.Get(defaultAuthorizationHeader)
Expand Down