Last active
March 25, 2018 04:19
-
-
Save Woody88/bc27a52360a9a33382ed077a31b6ca60 to your computer and use it in GitHub Desktop.
Salesforce Client Setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE OverloadedStrings #-} | |
import Data.Text (Text) | |
import Haskforce | |
import Haskforce.API.Resources | |
-- User Credential, they are fake so dont try those... | |
-- We have a type UserCred which will hold all of our salesforce user credential. | |
-- For security reason these values would be set as environment variable. | |
cred :: UserCred | |
cred = | |
UserCred (Just . Username $ "myuser@gmai.cm") | |
(Just . Userpassword $ "mypassword") | |
(Just . SecretKey $ "WbLqWxsdlxjFsf") | |
"3MVG9CEn_O3jvv0xZk.qhb_CMW4shC2zmPTGvFjv_3AjWufKnyiS.o" | |
"33345149459132" | |
-- Salesforce as three types of oauth request. We will be using the token one. | |
-- This TokenRequest type follows the salesforce structure. Requiring a Grant type | |
-- Oauth Type (UserPassword) and Credentials. The rest are optional values hence the reason | |
-- for the Nothing values. | |
tokenRequest :: TokenRequest | |
tokenRequest = | |
TokenRequest (GrantType Password) | |
(UserPassword) | |
cred | |
Nothing | |
Nothing | |
Nothing | |
Nothing | |
-- Salesforce Oauth endpoint | |
salesforceUrl :: BaseUrl | |
salesforceUrl = (BaseUrl Https "login.salesforce.com" 443 "/services/oauth2") | |
--- This function will return to us a SFClient which will contain an access token. | |
--- that we can use to perform actions later on. below is the login function type definition | |
--- login :: ClientRequest a => a -> SFBaseUrl -> SFApiNumber -> IO (Either ServantError SFClient) | |
sfclient :: IO (Either ServantError SFClient) | |
sfclient = login tokenRequest salesforceUrl "v42.0" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment