Skip to content

Commit ba52d33

Browse files
Ryan Kohlercodyoss
authored andcommitted
google: unexport private structs and funcs
These structs and funcs cannot be used by the end consumer. Unexporting them helps cleans up our documentation Change-Id: I2eadb69e87de912ac39f53e83cd9bdfe76a15e3e GitHub-Last-Rev: 60b58ee GitHub-Pull-Request: #479 Reviewed-on: https://go-review.googlesource.com/c/oauth2/+/293752 Reviewed-by: Cody Oss <codyoss@google.com> Trust: Cody Oss <codyoss@google.com> Trust: Tyler Bui-Palsulich <tbp@google.com> Run-TryBot: Cody Oss <codyoss@google.com> TryBot-Result: Go Bot <gobot@golang.org>
1 parent f145937 commit ba52d33

File tree

5 files changed

+22
-22
lines changed

5 files changed

+22
-22
lines changed

google/internal/externalaccount/basecredentials.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (ts tokenSource) Token() (*oauth2.Token, error) {
124124
if err != nil {
125125
return nil, err
126126
}
127-
stsRequest := STSTokenExchangeRequest{
127+
stsRequest := stsTokenExchangeRequest{
128128
GrantType: "urn:ietf:params:oauth:grant-type:token-exchange",
129129
Audience: conf.Audience,
130130
Scope: conf.Scopes,
@@ -134,12 +134,12 @@ func (ts tokenSource) Token() (*oauth2.Token, error) {
134134
}
135135
header := make(http.Header)
136136
header.Add("Content-Type", "application/x-www-form-urlencoded")
137-
clientAuth := ClientAuthentication{
137+
clientAuth := clientAuthentication{
138138
AuthStyle: oauth2.AuthStyleInHeader,
139139
ClientID: conf.ClientID,
140140
ClientSecret: conf.ClientSecret,
141141
}
142-
stsResp, err := ExchangeToken(ts.ctx, conf.TokenURL, &stsRequest, clientAuth, header, nil)
142+
stsResp, err := exchangeToken(ts.ctx, conf.TokenURL, &stsRequest, clientAuth, header, nil)
143143
if err != nil {
144144
return nil, err
145145
}

google/internal/externalaccount/clientauth.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ import (
1111
"net/url"
1212
)
1313

14-
// ClientAuthentication represents an OAuth client ID and secret and the mechanism for passing these credentials as stated in rfc6749#2.3.1.
15-
type ClientAuthentication struct {
14+
// clientAuthentication represents an OAuth client ID and secret and the mechanism for passing these credentials as stated in rfc6749#2.3.1.
15+
type clientAuthentication struct {
1616
// AuthStyle can be either basic or request-body
1717
AuthStyle oauth2.AuthStyle
1818
ClientID string
1919
ClientSecret string
2020
}
2121

22-
func (c *ClientAuthentication) InjectAuthentication(values url.Values, headers http.Header) {
22+
func (c *clientAuthentication) InjectAuthentication(values url.Values, headers http.Header) {
2323
if c.ClientID == "" || c.ClientSecret == "" || values == nil || headers == nil {
2424
return
2525
}

google/internal/externalaccount/clientauth_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestClientAuthentication_InjectHeaderAuthentication(t *testing.T) {
3737
"Content-Type": ContentType,
3838
}
3939

40-
headerAuthentication := ClientAuthentication{
40+
headerAuthentication := clientAuthentication{
4141
AuthStyle: oauth2.AuthStyleInHeader,
4242
ClientID: clientID,
4343
ClientSecret: clientSecret,
@@ -79,7 +79,7 @@ func TestClientAuthentication_ParamsAuthentication(t *testing.T) {
7979
headerP := http.Header{
8080
"Content-Type": ContentType,
8181
}
82-
paramsAuthentication := ClientAuthentication{
82+
paramsAuthentication := clientAuthentication{
8383
AuthStyle: oauth2.AuthStyleInParams,
8484
ClientID: clientID,
8585
ClientSecret: clientSecret,

google/internal/externalaccount/sts_exchange.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import (
1818
"golang.org/x/oauth2"
1919
)
2020

21-
// ExchangeToken performs an oauth2 token exchange with the provided endpoint.
21+
// exchangeToken performs an oauth2 token exchange with the provided endpoint.
2222
// The first 4 fields are all mandatory. headers can be used to pass additional
2323
// headers beyond the bare minimum required by the token exchange. options can
2424
// be used to pass additional JSON-structured options to the remote server.
25-
func ExchangeToken(ctx context.Context, endpoint string, request *STSTokenExchangeRequest, authentication ClientAuthentication, headers http.Header, options map[string]interface{}) (*STSTokenExchangeResponse, error) {
25+
func exchangeToken(ctx context.Context, endpoint string, request *stsTokenExchangeRequest, authentication clientAuthentication, headers http.Header, options map[string]interface{}) (*stsTokenExchangeResponse, error) {
2626

2727
client := oauth2.NewClient(ctx, nil)
2828

@@ -68,7 +68,7 @@ func ExchangeToken(ctx context.Context, endpoint string, request *STSTokenExchan
6868
if c := resp.StatusCode; c < 200 || c > 299 {
6969
return nil, fmt.Errorf("oauth2/google: status code %d: %s", c, body)
7070
}
71-
var stsResp STSTokenExchangeResponse
71+
var stsResp stsTokenExchangeResponse
7272
err = json.Unmarshal(body, &stsResp)
7373
if err != nil {
7474
return nil, fmt.Errorf("oauth2/google: failed to unmarshal response body from Secure Token Server: %v", err)
@@ -78,8 +78,8 @@ func ExchangeToken(ctx context.Context, endpoint string, request *STSTokenExchan
7878
return &stsResp, nil
7979
}
8080

81-
// STSTokenExchangeRequest contains fields necessary to make an oauth2 token exchange.
82-
type STSTokenExchangeRequest struct {
81+
// stsTokenExchangeRequest contains fields necessary to make an oauth2 token exchange.
82+
type stsTokenExchangeRequest struct {
8383
ActingParty struct {
8484
ActorToken string
8585
ActorTokenType string
@@ -93,8 +93,8 @@ type STSTokenExchangeRequest struct {
9393
SubjectTokenType string
9494
}
9595

96-
// STSTokenExchangeResponse is used to decode the remote server response during an oauth2 token exchange.
97-
type STSTokenExchangeResponse struct {
96+
// stsTokenExchangeResponse is used to decode the remote server response during an oauth2 token exchange.
97+
type stsTokenExchangeResponse struct {
9898
AccessToken string `json:"access_token"`
9999
IssuedTokenType string `json:"issued_token_type"`
100100
TokenType string `json:"token_type"`

google/internal/externalaccount/sts_exchange_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import (
1515
"testing"
1616
)
1717

18-
var auth = ClientAuthentication{
18+
var auth = clientAuthentication{
1919
AuthStyle: oauth2.AuthStyleInHeader,
2020
ClientID: clientID,
2121
ClientSecret: clientSecret,
2222
}
2323

24-
var tokenRequest = STSTokenExchangeRequest{
24+
var tokenRequest = stsTokenExchangeRequest{
2525
ActingParty: struct {
2626
ActorToken string
2727
ActorTokenType string
@@ -37,7 +37,7 @@ var tokenRequest = STSTokenExchangeRequest{
3737

3838
var requestbody = "audience=32555940559.apps.googleusercontent.com&grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Atoken-exchange&requested_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Aaccess_token&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdevstorage.full_control&subject_token=Sample.Subject.Token&subject_token_type=urn%3Aietf%3Aparams%3Aoauth%3Atoken-type%3Ajwt"
3939
var responseBody = `{"access_token":"Sample.Access.Token","issued_token_type":"urn:ietf:params:oauth:token-type:access_token","token_type":"Bearer","expires_in":3600,"scope":"https://www.googleapis.com/auth/cloud-platform"}`
40-
var expectedToken = STSTokenExchangeResponse{
40+
var expectedToken = stsTokenExchangeResponse{
4141
AccessToken: "Sample.Access.Token",
4242
IssuedTokenType: "urn:ietf:params:oauth:token-type:access_token",
4343
TokenType: "Bearer",
@@ -75,9 +75,9 @@ func TestExchangeToken(t *testing.T) {
7575
headers := http.Header{}
7676
headers.Add("Content-Type", "application/x-www-form-urlencoded")
7777

78-
resp, err := ExchangeToken(context.Background(), ts.URL, &tokenRequest, auth, headers, nil)
78+
resp, err := exchangeToken(context.Background(), ts.URL, &tokenRequest, auth, headers, nil)
7979
if err != nil {
80-
t.Fatalf("ExchangeToken failed with error: %v", err)
80+
t.Fatalf("exchangeToken failed with error: %v", err)
8181
}
8282

8383
if expectedToken != *resp {
@@ -95,7 +95,7 @@ func TestExchangeToken_Err(t *testing.T) {
9595

9696
headers := http.Header{}
9797
headers.Add("Content-Type", "application/x-www-form-urlencoded")
98-
_, err := ExchangeToken(context.Background(), ts.URL, &tokenRequest, auth, headers, nil)
98+
_, err := exchangeToken(context.Background(), ts.URL, &tokenRequest, auth, headers, nil)
9999
if err == nil {
100100
t.Errorf("Expected handled error; instead got nil.")
101101
}
@@ -179,5 +179,5 @@ func TestExchangeToken_Opts(t *testing.T) {
179179
inputOpts := make(map[string]interface{})
180180
inputOpts["one"] = firstOption
181181
inputOpts["two"] = secondOption
182-
ExchangeToken(context.Background(), ts.URL, &tokenRequest, auth, headers, inputOpts)
182+
exchangeToken(context.Background(), ts.URL, &tokenRequest, auth, headers, inputOpts)
183183
}

0 commit comments

Comments
 (0)