8 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/logger"
9 "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/requests"
12// stripToken is a helper function to obfuscate "access_token"
14func stripToken(endpoint string) string {
15 return stripParam("access_token", endpoint)
18// stripParam generalizes the obfuscation of a particular
19// query parameter - typically 'access_token' or 'client_secret'
20// The parameter's second half is replaced by '...' and returned
21// as part of the encoded query parameters.
22// If the target parameter isn't found, the endpoint is returned
24func stripParam(param, endpoint string) string {
25 u, err := url.Parse(endpoint)
27 logger.Errorf("error attempting to strip %s: %s", param, err)
32 values, err := url.ParseQuery(u.RawQuery)
34 logger.Errorf("error attempting to strip %s: %s", param, err)
38 if val := values.Get(param); val != "" {
39 // Truncate by at least half and allow for a maximum of 5 characters
40 values.Set(param, val[:min(len(val)/2, 5)]+"...")
41 u.RawQuery = values.Encode()
49// validateToken returns true if token is valid
50func validateToken(ctx context.Context, p Provider, accessToken string, header http.Header) bool {
51 if accessToken == "" || p.Data().ValidateURL == nil || p.Data().ValidateURL.String() == "" {
54 endpoint := p.Data().ValidateURL.String()
56 params := url.Values{"access_token": {accessToken}}
57 if hasQueryParams(endpoint) {
58 endpoint = endpoint + "&" + params.Encode()
60 endpoint = endpoint + "?" + params.Encode()
64 result := requests.New(endpoint).
68 if result.Error() != nil {
69 logger.Errorf("GET %s", stripToken(endpoint))
70 logger.Errorf("token validation request failed: %s", result.Error())
74 logger.Printf("%d GET %s %s", result.StatusCode(), stripToken(endpoint), result.Body())
76 if result.StatusCode() == 200 {
79 logger.Errorf("token validation request failed: status %d - %s", result.StatusCode(), result.Body())
83// hasQueryParams check if URL has query parameters
84func hasQueryParams(endpoint string) bool {
85 endpointURL, err := url.Parse(endpoint)
90 return len(endpointURL.RawQuery) != 0
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list