MCPcopy
hub / github.com/vouch/vouch-proxy / PrepareTokensAndClient

Function PrepareTokensAndClient

pkg/providers/common/common.go:33–53  ·  view source on GitHub ↗

PrepareTokensAndClient setup the client, usually for a UserInfo request

(r *http.Request, ptokens *structs.PTokens, setProviderToken bool, opts ...oauth2.AuthCodeOption)

Source from the content-addressed store, hash-verified

31
32// PrepareTokensAndClient setup the client, usually for a UserInfo request
33func PrepareTokensAndClient(r *http.Request, ptokens *structs.PTokens, setProviderToken bool, opts ...oauth2.AuthCodeOption) (*http.Client, *oauth2.Token, error) {
34 providerToken, err := cfg.OAuthClient.Exchange(context.TODO(), r.URL.Query().Get("code"), opts...)
35 if err != nil {
36 return nil, nil, err
37 }
38 ptokens.PAccessToken = providerToken.AccessToken
39
40 if setProviderToken {
41 if providerToken.Extra("id_token") != nil {
42 // Certain providers (eg. gitea) don't provide an id_token
43 // and it's not necessary for the authentication phase
44 ptokens.PIdToken = providerToken.Extra("id_token").(string)
45 } else {
46 log.Debugf("id_token missing - may not be supported by this provider")
47 }
48 }
49
50 log.Debugf("ptokens: accessToken length: %d, IdToken length: %d", len(ptokens.PAccessToken), len(ptokens.PIdToken))
51 client := cfg.OAuthClient.Client(context.TODO(), providerToken)
52 return client, providerToken, err
53}
54
55// MapClaims populate CustomClaims from userInfo for each configure claims header
56func MapClaims(claims []byte, customClaims *structs.CustomClaims) error {

Callers 8

GetUserInfoMethod · 0.92
GetUserInfoMethod · 0.92
GetUserInfoMethod · 0.92
GetUserInfoMethod · 0.92
GetUserInfoMethod · 0.92
GetUserInfoMethod · 0.92
GetUserInfoMethod · 0.92
GetUserInfoMethod · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected