SMS with two factor authentification

Forum Home Forums Understanding the Software SMS with two factor authentification

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #17357
    oley
    Participant

    Hi,

    I need to send an SMS about a discreet channel change.
    I have modems that can send SMS messages, but they work with double authorization: first, a request for a token with access data, and then sending an SMS with the token.
    An example PS script looks like this:

    
    $ip = "172.16.1.2:81"
    $username = "admin"
    $password = "pass"
    $phoneNumber = "+48123456789"
    $messageText = "Test sms"
    $modemId = "2-1"
    
    try {
        $loginUrl = "http://$ip/api/login"
        $loginBody = @{ username = $username; password = $password } | ConvertTo-Json
    
        $loginResponse = Invoke-RestMethod -Uri $loginUrl -Method Post -Body $loginBody -ContentType "application/json"
        $token = $loginResponse.token
    } catch {
        exit 1
    }
    
    try {
        $smsUrl = "http://$ip/api/messages/actions/send"
        $smsBody = @{ data = @{ number = $phoneNumber; message = $messageText; modem = $modemId } } | ConvertTo-Json -Depth 3
    
        $smsResponse = Invoke-RestMethod -Uri $smsUrl -Method Post -Body $smsBody -ContentType "application/json" -Headers @{ Authorization = "Bearer $token" }
    } catch {
        exit 1
    }
    

    I don’t really see the possibility of standard notification from Rapid SCADA.
    I could write this code in C# and use it to send SMS messages.

    Please give me some tips on how to approach this.

    Best regards
    Przemek

    #17358
    Mikhail
    Moderator

    Hi,

    Check DrvHttpNotif driver. It can send HTTP requests according to commands.
    To send a sequence of commands, use Auto Control Module.
    Ask for additional info if needed.

    #17359
    Mikhail
    Moderator

    Probably, the existing driver does not preserve a token returned by the 1st request.

    #17360
    Mikhail
    Moderator

    Is it possible for you to select an alternative service that needs only one HTTP request to send a message?

    #17361
    oley
    Participant

    Thank you,
    yes I will provide simple proxy service which can become single request and make two-factor request.

    #17362
    oley
    Participant

    Is there a possibility to simply test if this solution works?
    If I had the service which works like:

    Invoke-RestMethod -Uri "http://localhost:5150/send-sms" -Method Post -Headers @{ "Content-Type" = "application/json" } -Body '{"phoneNumber":"+48111111111","message":"Test API"}'

    and put Url into DrvHttpNotif with content type json and so on. How to send a test message?

    #17363
    oley
    Participant
    <?xml version="1.0" encoding="utf-8"?>
    <NotifDeviceConfig>
      <Uri>http://localhost:5150/send-sms</Uri>
      <Method>Post</Method>
      <Headers>
        <Header name="Content-Type" value="application/json" />
      </Headers>
      <Content>{
      "phoneNumber": "+486011111",
      "message": "SCADA"
    }
    </Content>
      <ContentType>application/json</ContentType>
      <ContentEscaping>EncodeJson</ContentEscaping>
      <ParamEnabled>false</ParamEnabled>
      <ParamBegin>[</ParamBegin>
      <ParamEnd>]</ParamEnd>
      <AddrSep>;</AddrSep>
    </NotifDeviceConfig>
    • This reply was modified 1 month, 1 week ago by Mikhail.
    #17364
    oley
    Participant

    One more request: could you remove the phone number from the configuration I sent? I can’t edit my message.

    #17366
    oley
    Participant

    I made it work.
    I created a proxy service that accepts POST requests and sends SMS messages with two-factor authentication based on them.
    Since the request is in JSON format, I have to use [param] instead of {param} for the parameters.
    The Headers tab probably refers to the response, because when I set Content-Type there, I kept getting the error: “Error creating request: Misused header name, ‘Content-Type’. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.”

    I will send something like: {CnlName} on {EvDev} at {EvObj} changed value to {CnlVal}

    I suppose this should be Channel Data Change Trigger and than Command with code “Request” to my Notifier device.
    Now is the question: how to send SMS to a recipient from the address book?

    #17368
    Mikhail
    Moderator

    I’ve checked the source code of the driver.
    Parameters (phone number and text) can be inserted in the request URL and content.
    This is so weird that the service requires to insert phone number in the request header. Usually headers contain auth tokens and similar things.
    P.S. Phone number in the above was changed.

    • This reply was modified 1 month, 1 week ago by Mikhail.
    #17369
    Mikhail
    Moderator

    You wrote
    -Body '{"phoneNumber":"+48111111111","message":"Test API"}'
    It’s related to the request contents, not headers.

    #17370
    Mikhail
    Moderator

    Example of the content:

    {
        "from": "SCADA",
        "to": [phone], 
        "message": "[text]" 
    }

    Set ParamEnabled to true.

    #17372
    Mikhail
    Moderator

    To use a phone book, see the available commands in the driver description on the Drivers page.

    #17373
    oley
    Participant

    Hi Mikhail,

    thank you. I can send an SMS from SCADA with simple “Request” command. It works.
    Now I want to use it as notifier. So I have some contacts in the address book.
    I have Channel Data Change Trigger in ACM.
    How to connect this together? Command to device DrvHttpNotif? But how to access this address book?

    #17375
    oley
    Participant

    Can’t find any doc for this driver. Can you give me a link to this description?

Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.