Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend/fix : token based auth in value first api #750

Merged
merged 1 commit into from
Feb 5, 2025
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ sendOTP smsCfg SendSMSReq {..} = do
otpSmsTemp = smsBody
phone = phoneNumber
senderName = sender
username <- decrypt smsCfg.username
password <- decrypt smsCfg.password
res <- MVF.sendOTPApi urlAddress username password otpSmsTemp phone senderName
token <- decrypt smsCfg.token
res <- MVF.sendOTPApi urlAddress token otpSmsTemp phone senderName

return $ returnSmsResultMVF res

Expand Down
5 changes: 2 additions & 3 deletions lib/mobility-core/src/Kernel/External/SMS/MyValueFirst/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import Servant
type ServiceAPI =
"smpp"
:> "sendsms"
:> MandatoryQueryParam "username" Text
:> MandatoryQueryParam "password" Text
:> Header "Authorization" Text
:> MandatoryQueryParam "from" Text
:> MandatoryQueryParam "to" Text
:> MandatoryQueryParam "text" Text
Expand All @@ -37,4 +36,4 @@ serviceAPI :: Proxy ServiceAPI
serviceAPI = Proxy

submitSms :: SubmitSms -> ET.EulerClient SubmitSmsRes
submitSms SubmitSms {..} = ET.client serviceAPI username password from to text
submitSms SubmitSms {..} = ET.client serviceAPI (Just $ "Bearer " <> token) from to text
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import Kernel.Prelude
data MyValueFirstCfg = MyValueFirstCfg
{ username :: EncryptedField 'AsEncrypted Text,
password :: EncryptedField 'AsEncrypted Text,
url :: BaseUrl
url :: BaseUrl,
token :: EncryptedField 'AsEncrypted Text
}
deriving (Show, Eq, Generic, ToJSON, FromJSON)
30 changes: 15 additions & 15 deletions lib/mobility-core/src/Kernel/External/SMS/MyValueFirst/Flow.hs
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,15 @@ sendOTPApi ::
Text ->
Text ->
Text ->
Text ->
m SubmitSmsRes
sendOTPApi url username password otpSmsTemplate phoneNumber sender = do
sendOTPApi url token otpSmsTemplate phoneNumber sender = do
submitSms
url
SubmitSms
{ username = username,
password = password,
from = sender,
{ from = sender,
to = phoneNumber,
text = otpSmsTemplate
text = otpSmsTemplate,
token = token
}

sendSms ::
Expand All @@ -73,15 +71,17 @@ sendSms ::
sendSms smsCfg smsTemplate phoneNumber = do
let smsCred = smsCfg.credConfig
url = smsCfg.url
submitSms
url
SubmitSms
{ username = smsCred.username,
password = smsCred.password,
from = smsCfg.sender,
to = phoneNumber,
text = smsTemplate
}
case smsCred.token of
Just token -> do
submitSms
url
SubmitSms
{ from = smsCfg.sender,
to = phoneNumber,
text = smsTemplate,
token = token
}
Nothing -> throwError $ InternalError "token is null"

checkSmsResult :: (Log m, MonadThrow m) => SubmitSmsRes -> m ()
checkSmsResult =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ import Servant

data SubmitSms = SubmitSms
{ -- | Login of myfirstvalue.com account.
username :: Text,
-- | Password of that account.
password :: Text,
-- | Author name assigned to SMS.
from :: Text,
-- | Phone number.
to :: Text,
-- | SMS contents.
text :: Text
text :: Text,
-----
token :: Text
}
deriving (Show)

Expand Down
3 changes: 2 additions & 1 deletion lib/mobility-core/src/Kernel/Sms/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ data SmsSessionConfig = SmsSessionConfig
data SmsCredConfig = SmsCredConfig
{ username :: Text, -- FIXME? Do we need to reuse Servant's one?
password :: Text, -- idem
otpHash :: Text
otpHash :: Text,
token :: Maybe Text
}
deriving (Generic, FromDhall)

Expand Down