MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / verifyGoogle

Function verifyGoogle

rest/google.go:54–80  ·  view source on GitHub ↗
(idToken string, allowedAppID []string)

Source from the content-addressed store, hash-verified

52}
53
54func verifyGoogle(idToken string, allowedAppID []string) (*GoogleResponse, error) {
55 destUrl := googleTokenInfoURL + idToken
56
57 res, err := http.Get(destUrl)
58 if err != nil {
59 return nil, base.HTTPErrorf(http.StatusGatewayTimeout, "Unable to send request to Google API: %v", err)
60 }
61 defer func() { _ = res.Body.Close() }()
62
63 decoder := base.JSONDecoder(res.Body)
64
65 var response GoogleResponse
66 err = decoder.Decode(&response)
67 if err != nil {
68 return nil, base.HTTPErrorf(http.StatusBadGateway, "Invalid response from Google token verifier")
69 }
70
71 if response.ErrorDescription != "" {
72 return nil, base.NewHTTPError(http.StatusUnauthorized, response.ErrorDescription)
73 }
74
75 if !isValidAud(response.Aud, allowedAppID) {
76 return nil, base.HTTPErrorf(http.StatusUnauthorized, "Invalid application id, please add it in the config")
77 }
78
79 return &response, nil
80}
81
82func isValidAud(aud string, allowedAppID []string) bool {
83 for _, s := range allowedAppID {

Callers 1

handleGooglePOSTMethod · 0.85

Calls 7

HTTPErrorfFunction · 0.92
JSONDecoderFunction · 0.92
NewHTTPErrorFunction · 0.92
isValidAudFunction · 0.85
CloseMethod · 0.65
DecodeMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected