github.com/Axway/agent-sdk@v1.1.101/pkg/authz/oauth/clientsecretbasicauthenticator.go (about)

     1  package oauth
     2  
     3  import (
     4  	"encoding/base64"
     5  	"fmt"
     6  	"net/url"
     7  )
     8  
     9  const (
    10  	basicAuthHeaderTemplate = "Basic %s"
    11  )
    12  
    13  type clientSecretBasicAuthenticator struct {
    14  	clientID     string
    15  	clientSecret string
    16  	scope        string
    17  }
    18  
    19  func (p *clientSecretBasicAuthenticator) prepareRequest() (url.Values, map[string]string, error) {
    20  	v := url.Values{
    21  		metaGrantType: []string{GrantTypeClientCredentials},
    22  	}
    23  
    24  	if p.scope != "" {
    25  		v.Add(metaScope, p.scope)
    26  	}
    27  
    28  	token := base64.StdEncoding.EncodeToString([]byte(p.clientID + ":" + p.clientSecret))
    29  	headers := map[string]string{
    30  		hdrAuthorization: fmt.Sprintf(basicAuthHeaderTemplate, token),
    31  	}
    32  	return v, headers, nil
    33  }