@@ -12,7 +12,12 @@ import (
1212)
1313
1414// #nosec G101 -- False positive - no hardcoded credentials.
15- const tokensApi = "api/v1/tokens"
15+ const (
16+ // jfrog-ignore - not a real token
17+ tokensApi = "api/v1/tokens"
18+ // jfrog-ignore - not a real token
19+ oidcTokensApi = "api/v1/oidc/token"
20+ )
1621
1722type TokenService struct {
1823 client * jfroghttpclient.JfrogHttpClient
@@ -27,6 +32,21 @@ type CreateTokenParams struct {
2732 Description string `json:"description,omitempty"`
2833}
2934
35+ type CreateOidcTokenParams struct {
36+ GrantType string `json:"grant_type,omitempty"`
37+ SubjectTokenType string `json:"subject_token_type,omitempty"`
38+ OidcTokenID string `json:"subject_token,omitempty"`
39+ ProviderName string `json:"provider_name,omitempty"`
40+ ProjectKey string `json:"project_key,omitempty"`
41+ JobId string `json:"job_id,omitempty"`
42+ RunId string `json:"run_id,omitempty"`
43+ Repo string `json:"repo,omitempty"`
44+ ApplicationKey string `json:"application_key,omitempty"`
45+ Audience string `json:"audience,omitempty"`
46+ IdentityMappingName string `json:"identity_mapping_name,omitempty"`
47+ IncludeReferenceToken * bool `json:"include_reference_token,omitempty"`
48+ }
49+
3050func NewCreateTokenParams (params CreateTokenParams ) CreateTokenParams {
3151 return CreateTokenParams {CommonTokenParams : params .CommonTokenParams , IncludeReferenceToken : params .IncludeReferenceToken }
3252}
@@ -84,6 +104,26 @@ func (ps *TokenService) handleUnauthenticated(params CreateTokenParams, httpDeta
84104 return errorutils .CheckErrorf ("cannot create access token without credentials" )
85105}
86106
107+ func (ps * TokenService ) ExchangeOidcToken (params CreateOidcTokenParams ) (auth.OidcTokenResponseData , error ) {
108+ var tokenInfo auth.OidcTokenResponseData
109+ httpDetails := ps .ServiceDetails .CreateHttpClientDetails ()
110+ httpDetails .SetContentTypeApplicationJson ()
111+ requestContent , err := json .Marshal (params )
112+ if errorutils .CheckError (err ) != nil {
113+ return tokenInfo , err
114+ }
115+ url := fmt .Sprintf ("%s%s" , ps .ServiceDetails .GetUrl (), oidcTokensApi )
116+ resp , body , err := ps .client .SendPost (url , requestContent , & httpDetails )
117+ if err != nil {
118+ return tokenInfo , err
119+ }
120+ if err = errorutils .CheckResponseStatusWithBody (resp , body , http .StatusOK ); err != nil {
121+ return tokenInfo , fmt .Errorf ("failed to exchange OIDC token: %w" , err )
122+ }
123+ err = json .Unmarshal (body , & tokenInfo )
124+ return tokenInfo , errorutils .CheckError (err )
125+ }
126+
87127func prepareForRefresh (p CreateTokenParams ) (* CreateTokenParams , error ) {
88128 // Validate provided parameters
89129 if p .RefreshToken == "" {
0 commit comments