Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions force/force.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,12 @@ func CreateWithAccessToken(version, clientId, accessToken, instanceUrl string) (
return forceApi, nil
}

func CreateWithRefreshToken(version, clientId, accessToken, instanceUrl string) (*ForceApi, error) {
func CreateWithRefreshToken(version, clientId, clientSecret, refreshToken, environment string) (*ForceApi, error) {
oauth := &forceOauth{
clientId: clientId,
AccessToken: accessToken,
InstanceUrl: instanceUrl,
clientSecret: clientSecret,
refreshToken: refreshToken,
environment: environment,
}

forceApi := &ForceApi{
Expand All @@ -104,13 +105,8 @@ func CreateWithRefreshToken(version, clientId, accessToken, instanceUrl string)
oauth: oauth,
}

// obtain access token
if err := forceApi.RefreshToken(); err != nil {
return nil, err
}

// We need to check for oath correctness here, since we are not generating the token ourselves.
if err := forceApi.oauth.Validate(); err != nil {
// Init oauth
if err := forceApi.oauth.AuthenticateWithRefreshToken(); err != nil {
return nil, err
}

Expand Down
16 changes: 16 additions & 0 deletions force/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

const (
grantType = "password"
grantTypeRefreshToken = "refresh_token"
loginUri = "https://login.salesforce.com/services/oauth2/token"
testLoginUri = "https://test.salesforce.com/services/oauth2/token"

Expand Down Expand Up @@ -60,6 +61,21 @@ func (oauth *forceOauth) Authenticate() error {
"password": {fmt.Sprintf("%v%v", oauth.password, oauth.securityToken)},
}

return oauth.AuthenticateWithPayload(payload)
}

func (oauth *forceOauth) AuthenticateWithRefreshToken() error {
payload := url.Values{
"grant_type": {grantTypeRefreshToken},
"client_id": {oauth.clientId},
"client_secret": {oauth.clientSecret},
"refresh_token": {oauth.refreshToken},
}

return oauth.AuthenticateWithPayload(payload)
}

func (oauth *forceOauth) AuthenticateWithPayload(payload url.Values) error {
// Build Uri
uri := loginUri
if oauth.environment == "sandbox" {
Expand Down