Skip to content

Commit da064ac

Browse files
committed
refactor(telkomsel): centralize authentication and encryption constants in config
feat(config): add new constants for CIAM base URL, realm, client ID, client secret, redirect URI, auth user agent, and encryption password fix(telkomsel): use centralized constants for authentication and encryption parameters
1 parent 54a6b92 commit da064ac

3 files changed

Lines changed: 29 additions & 21 deletions

File tree

config/config.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,15 @@ const (
3333
OfferId = "0fc00fd41bcd26376d806925d746705e"
3434
DefaultPayment = "qris"
3535
MaxRetries = 3
36-
WebAppVersion = "2.0.0"
37-
ChromePreset = "chrome-145"
36+
WebAppVersion = "2.0.0"
37+
ChromePreset = "chrome-145"
38+
CiamBaseURL = "https://ciam.telkomsel.com"
39+
CiamRealm = "tsel"
40+
ClientID = "e7126474617aa39eb9e484233c9b0649"
41+
ClientSecret = "P@ssw0rd"
42+
RedirectURI = "https://my.telkomsel.com/web/callback"
43+
AuthUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36"
44+
EncryptionPassword = "production"
3845
)
3946

4047
var Verbose bool

telkomsel/auth.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ func (a *Auth) Login(ctx context.Context, localPhone string, otpCallback OTPCall
4646
},
4747
}
4848

49-
userAgent := []string{"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/145.0.0.0 Safari/537.36"}
50-
clientID := "e7126474617aa39eb9e484233c9b0649"
49+
userAgent := []string{config.AuthUserAgent}
50+
clientID := config.ClientID
5151

5252
log.Println("[Login] Requesting OTP...")
5353
reqBody1 := []byte("")
@@ -56,8 +56,8 @@ func (a *Auth) Login(ctx context.Context, localPhone string, otpCallback OTPCall
5656
"Accept": []string{"application/json"},
5757
"Dnt": []string{"1"},
5858
"Sec-Ch-Ua-Mobile": []string{"?0"},
59-
"Origin": []string{"https://my.telkomsel.com"},
60-
"Referer": []string{"https://my.telkomsel.com/"},
59+
"Origin": []string{config.LoginURL},
60+
"Referer": []string{config.LoginURL + "/"},
6161
"Sec-Fetch-Site": []string{"same-site"},
6262
"Sec-Fetch-Mode": []string{"cors"},
6363
"Sec-Fetch-Dest": []string{"empty"},
@@ -71,7 +71,7 @@ func (a *Auth) Login(ctx context.Context, localPhone string, otpCallback OTPCall
7171
"Priority": []string{"u=1, i"},
7272
}
7373

74-
authURL := "https://ciam.telkomsel.com/iam/v1/realms/tsel/authenticate?authIndexType=service&authIndexValue=phoneLogin"
74+
authURL := fmt.Sprintf("%s/iam/v1/realms/%s/authenticate?authIndexType=service&authIndexValue=phoneLogin", config.CiamBaseURL, config.CiamRealm)
7575

7676
req1, _ := http.NewRequestWithContext(ctx, "POST", authURL, bytes.NewReader(reqBody1))
7777
req1.Header = headers1
@@ -136,9 +136,9 @@ func (a *Auth) Login(ctx context.Context, localPhone string, otpCallback OTPCall
136136
"Accept": []string{"application/json"},
137137
"Dnt": []string{"1"},
138138
"Sec-Ch-Ua-Mobile": []string{"?0"},
139-
"Origin": []string{"https://my.telkomsel.com"},
140-
"Referer": []string{"https://my.telkomsel.com/"},
141-
"Am-Clientid": []string{clientID},
139+
"Origin": []string{config.LoginURL},
140+
"Referer": []string{config.LoginURL + "/"},
141+
"Am-Clientid": []string{config.ClientID},
142142
"Content-Type": []string{"application/json"},
143143
"Sec-Fetch-Site": []string{"same-site"},
144144
"Sec-Fetch-Mode": []string{"cors"},
@@ -184,17 +184,17 @@ func (a *Auth) Login(ctx context.Context, localPhone string, otpCallback OTPCall
184184

185185
log.Println("[Login] Authorizing...")
186186
authzParams := url.Values{}
187-
authzParams.Add("client_id", clientID)
187+
authzParams.Add("client_id", config.ClientID)
188188
authzParams.Add("nonce", "true")
189-
authzParams.Add("redirect_uri", "https://my.telkomsel.com/web/callback")
189+
authzParams.Add("redirect_uri", config.RedirectURI)
190190
authzParams.Add("response_type", "code")
191191
authzParams.Add("scope", "profile openid phone identifier")
192192

193-
authzURL := "https://ciam.telkomsel.com/iam/v1/oauth2/realms/tsel/authorize?" + authzParams.Encode()
193+
authzURL := fmt.Sprintf("%s/iam/v1/oauth2/realms/%s/authorize?%s", config.CiamBaseURL, config.CiamRealm, authzParams.Encode())
194194
headers3 := http.Header{
195195
"User-Agent": userAgent,
196196
"Accept": []string{"application/json"},
197-
"Referer": []string{"https://my.telkomsel.com/"},
197+
"Referer": []string{config.LoginURL + "/"},
198198
"Dnt": []string{"1"},
199199
"Sec-Ch-Ua-Mobile": []string{"?0"},
200200
"Sec-Ch-Ua": []string{`"Not:A-Brand";v="99", "Google Chrome";v="145", "Chromium";v="145"`},
@@ -238,20 +238,20 @@ func (a *Auth) Login(ctx context.Context, localPhone string, otpCallback OTPCall
238238

239239
log.Println("[Login] Requesting access token...")
240240
tokenParams := url.Values{}
241-
tokenParams.Add("client_id", clientID)
242-
tokenParams.Add("client_secret", "P@ssw0rd")
241+
tokenParams.Add("client_id", config.ClientID)
242+
tokenParams.Add("client_secret", config.ClientSecret)
243243
tokenParams.Add("code", code)
244244
tokenParams.Add("grant_type", "authorization_code")
245-
tokenParams.Add("redirect_uri", "https://my.telkomsel.com/web/callback")
245+
tokenParams.Add("redirect_uri", config.RedirectURI)
246246
tokenParams.Add("response_type", "code")
247247

248-
tokenURL := "https://ciam.telkomsel.com/iam/v1/oauth2/realms/tsel/access_token?" + tokenParams.Encode()
248+
tokenURL := fmt.Sprintf("%s/iam/v1/oauth2/realms/%s/access_token?%s", config.CiamBaseURL, config.CiamRealm, tokenParams.Encode())
249249

250250
headers4 := http.Header{
251251
"User-Agent": userAgent,
252252
"Accept": []string{"application/json"},
253-
"Origin": []string{"https://my.telkomsel.com"},
254-
"Referer": []string{"https://my.telkomsel.com/"},
253+
"Origin": []string{config.LoginURL},
254+
"Referer": []string{config.LoginURL + "/"},
255255
"Content-Type": []string{"application/x-www-form-urlencoded"},
256256
"Content-Length": []string{"0"},
257257
"Dnt": []string{"1"},

telkomsel/crypto.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"encoding/base64"
88
"encoding/hex"
99
"encoding/json"
10+
"telkomsel-bot/config"
1011
"time"
1112
)
1213

@@ -29,7 +30,7 @@ func evpBytesToKey(password string, keyLen, ivLen int) (key, iv []byte) {
2930

3031
func EncryptPayload(payload string) string {
3132
_ = hex.EncodeToString([]byte(payload))
32-
key, iv := evpBytesToKey("production", 16, 16)
33+
key, iv := evpBytesToKey(config.EncryptionPassword, 16, 16)
3334

3435
block, err := aes.NewCipher(key)
3536
if err != nil {

0 commit comments

Comments
 (0)