Results 1 to 5 of 5
  1. #1

    * Implement an authentication web service PHP Script

    hello guys..!

    i have an Account with internap. i am planning to stream live videos through them. and i have 2 websites to get my feeds.
    i saw that in internap they have php Authntication method Which will Allow me to block the leechers.

    As per thier web, they discribe thier authntication method works
    "Multiple authentication systems can be used to control access to your media.
    When a user tries to view secure media, Internapís Authentication Service passes the call to the remote web service specified by the customer.
    This web service call is made in real-time and will only allow authorized users to access once the reply is received from the content owner."

    And also they stated that

    "Three Methods of Authentication Controls in thier php script
    -Tokens: Link into any web service by requesting information from the user such as username and password or a time stamp for expiring links.
    -IP Addresses: Only allow users in a specific IP block to view your media.
    - Referrers: Ensure that links to media only come from websites authorized by you.

    You can use any combination of these three attributes to accept or reject requests to view secure media. "


    source : http://www.internapcdn.com/authentication/index.html

    I need a little help with the Web service authentication php script. i am beginner and i have lot of doubts with it.
    i want to play my videos from my 2 domain only. For example, if i need to play this videos from webhostingtalk.com and internap.com .
    how i will modify the authentication.php? Should i edit WSDL file too..? i want to block all the other websites from playing this content.
    i read on internap website that it is possible to do so with referer blocking method or a time stamp for expiring links. (token)

    please help me to edit these files. i will paste the files, the ones i downloaded from internap for webservice Authentication
    the files are :

    1.Authentication.php
    2.Authentication.wsdl

    =================================================================
    Authentication.php
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


    PHP Code:
    <?php

    // Version 1.0

    // This is a sample PHP to implement an authentication web service
    // VitalStream's servers will call your web service to Accept or Reject connections
    // If code is to provide a starting point for a developer wanting to create their own
    // authentication rules for their streaming.
    //
    // If you modify this script or create a new one make sure you keep your SOAP messages compatible
    // with the definitions inside Authentication.wsdl
    //
    // If you change the WSDL definitions or SOAP structure the client may not understand how to 
    // interact with your code

    header("Content-Type: text/xml");    // The client calling this code expects XML content-type

    // Create a soap server object based off the standard WSDL provided.
    $server = new soapserver("Authentication.wsdl", array('encoding'=>'UTF-8'));


    /* function: Authenticate
     * Purpose: This is the method that will be called during each connection
     *            Use one of the input parameters as a criteria to authenticate the client
     * 
     * Comments: Keep the duration between entering and exiting this function to a minimum
     *             The client cannot begin streaming until you send back a result
     *             If an extremely long time has lapsed the web service client may also terminate the
     *           connection 
     *
     * Inputs: 
     *            (strings)account        The name of the VitalStream account associated with this request
     *                                    This could be useful if you have multiple accounts, otherwise is will 
     *                                    always contain the same value.
     * 
     *            (strings)token        This is the unique string that was passed into the Player
     *                                    This can be a alpha numeric and should not be predictable
     * 
     *            (strings)referrer    This is the referrer passed to the server, usually this is the url 
     *                                    to the .swf
     * 
     *            (strings)sourceURL    This is the full URL being requested from the server
     * 
     *            (strings)ip    This is the IP of the client connecting to the server
     * 
     * Output: 
     *            (int)0    Reject Access 
     *            (int)1    Accept Access
     */

    function Authenticate($account$token$referrer$sourceurl$ip)
    {
        
    // A very simple demonstration of how you can accept/reject connection on specific criteria
        // In this case if the token is an even number we will allow access, if the number is odd we reject
        
    if($token == 0) { $retval "1"; }
        return 
    $retval;    // return ACCEPT(1) or REJECT(0)
    }


    // map the SOAP operation to the appropriate PHP function above
    $server->addFunction("Authenticate");

    // This is just some extra code to show what web service function is available if you browse this PHP
    if ($_SERVER["REQUEST_METHOD"] == "POST"// If this is a post from the web service client then handle soap
    {
      
    $server->handle();    // process the soap

    else    
    // this is probably a browser querying what function is available in this php
    {
      echo 
    "This SOAP server can handle following functions: ";
      
    $functions $server->getFunctions();
      foreach(
    $functions as $func
        {
            echo 
    $func "\n";
        }
    }



    ?>




    ===============================================================

    2nd file is Authentication.wsdl
    =============================================================

    PHP Code:
    <?xml version="1.0" ?> 
    <definitions name="VSAuthentication" targetNamespace="http://vitalstream.com/webservices" xmlns:typens="http://vitalstream.com/webservices" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns="http://schemas.xmlsoap.org/wsdl/">
    <types>
    <xsd:schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://vitalstream.com/webservices">
    </xsd:schema>
    </types>
    <message name="doAuthenticate">
      <part name="strAccount" type="xsd:string" /> 
      <part name="strToken" type="xsd:string" /> 
      <part name="strReferrer" type="xsd:string" /> 
      <part name="strSourceURL" type="xsd:string" /> 
      <part name="strClientIP" type="xsd:string" /> 
      </message>
    <message name="doAuthenticateResponse">
      <part name="Result" type="xsd:int" /> 
    </message>
    <portType name="VSAuthenticationPort">
    <operation name="Authenticate">
      <input message="typens:doAuthenticate" /> 
      <output message="typens:doAuthenticateResponse" /> 
      </operation>
      </portType>
    <binding name="VSAuthenticationBinding" type="typens:VSAuthenticationPort">
      <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http" /> 
    <operation name="Authenticate">
      <soap:operation soapAction="http://vitalstream.com/webservices/Authenticate" /> 
    <input>
      <soap:body use="encoded" namespace="http://vitalstream.com/webservices" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> 
      </input>
    <output>
      <soap:body use="encoded" namespace="http://vitalstream.com/webservices" encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" /> 
      </output>
      </operation>
      </binding>
    <service name="VSAuthenticationService">
    <port name="VSAuthenticationPort" binding="typens:VSAuthenticationBinding">
      <soap:address location="http://localhost/VSAuthenticationWS/php/Authentication.php" /> 
      </port>
      </service>
    </definitions>
    Once again Thank you so Much

    With regards

    E Buddy

  2. #2
    Join Date
    Jan 2006
    Location
    Athens, Greece
    Posts
    1,479
    Possibly depending on your authentication method, either with ip:
    PHP Code:
    function Authenticate($account$token$referrer$sourceurl$ip)
    {
        
    $retval "0";
        if (
    $ip == "192.168.1.1"$retval "1";
        return 
    $retval;    // return ACCEPT(1) or REJECT(0)

    Or with referer:
    PHP Code:
    function Authenticate($account$token$referrer$sourceurl$ip)
    {
        
    $retval "0";
        if (
    preg_match('/^http:\/\/(www\.)?domain\.com\/?(.*)$/'$referrer$retval "1";
        return 
    $retval;    // return ACCEPT(1) or REJECT(0)

    I wouldn't use the referer, it can easily be spoofed.

  3. #3

    Help Me

    Hello Steve
    Thanks for the response. As i said in my earlier post, i am just a beginer in PHP,
    i am still confused aganist these codes. In your Post You recommended that IP Authntication method is better than Referer method and you also stated that Referer method Can be spoofed Easily.
    But my Problem is if we go with IP Authntication method,
    it will give access to the users in a specific IP block to view my media. let say i gave access to USA IP range and UK ip range.
    So all the viewers from those countries will get the accsess no matter they are seeing the content from leeched web site or my website.
    I would like to limit my useres to view the content from myown website, even though the referrer authntication can easily be spoofed. I would like to have at least referrer protection.
    i have couple questions in that connection.
    1. will this script allow me to give my website IP ? (instead of giving specific Ip Block)
    let say webhostingtalk.com ip is 69.20.126.9 and internap.com Ip is 64.94.4.195.
    So can i set these two ips ( 69.20.126.9, 64.94.4.195 ) in the php script .
    The users comming from those websites only can view the content.

    is this code looks right..?

    PHP Code:
    function Authenticate($account$token$referrer$sourceurl$ip)
    {
    $retval "0";
    if (
    $ip == "69.20.126.9"$retval "1";
    return 
    $retval// return ACCEPT(1) or REJECT(0)

    {
    $retval "0";
    if (
    $ip == "64.94.4.195"$retval "1";
    return 
    $retval// return ACCEPT(1) or REJECT(0)

    2. I have another question, the above one not work like what i was thinking, i have to go to the 2 nd method,
    the Referal Authntication. let say i would like to allow the users from 2 website webhostingtalk.com , and internap.com

    is that the case this code i edited is right..? please help me

    PHP Code:
    function Authenticate($account$token$referrer$sourceurl$ip)
    {
    $retval "0";
    if (
    preg_match('/^http:\/\/(www\.)?webhostingtalk\.com\/?(.*)$/'$referrer$retval "1";
    return 
    $retval// return ACCEPT(1) or REJECT(0)

    {
    $retval "0";
    if (
    preg_match('/^http:\/\/(www\.)?internap\.com\/?(.*)$/'$referrer$retval "1";
    return 
    $retval// return ACCEPT(1) or REJECT(0)

    Thanks in Advance

    with regards
    E Buddy
    Last edited by ebuddy; 02-04-2008 at 02:57 PM.

  4. #4
    Join Date
    Jan 2006
    Location
    Athens, Greece
    Posts
    1,479
    If the client who asks for the content is a server - the one where the video is being pulled from,
    its safe to use IP authentication. If the IP is the one of the user, whatever then it's the other way around.

    You should ask internap or start doing some checks.

    If you want multiple ips:
    PHP Code:
    function Authenticate($account$token$referrer$sourceurl$ip

    $retval "0";
    $arr = array("69.20.126.9","1.1.1.1");
    if (
    in_array($ip$arr)) $retval "1"
    return 
    $retval;


  5. #5

    Plz help Me..!

    steve thank you so much for the quick response...!

    i think i have to stick with referrer Authntication method and the token authntication method.
    the internap says "You can use any combination of these three attributes to accept or reject requests to view secure media. "and in thier token method a time stamp for expiring links option metthod available.

    Can you please tell me the below php is correct for referer method. Am i editted correctly..? i used two websites webhostingtalk.com, internap.com for example. and can you tell me how would i write a code for token (a time stamp for expiring links) thanks in advance

    PHP Code:
    function Authenticate($account$token$referrer$sourceurl$ip

    $retval "0"
    if (
    preg_match('/^http:\/\/(www\.)?webhostingtalk\.com\/?(.*)$/'$referrer$retval "1"
    return 
    $retval// return ACCEPT(1) or REJECT(0) 


    $retval "0"
    if (
    preg_match('/^http:\/\/(www\.)?internap\.com\/?(.*)$/'$referrer$retval "1"
    return 
    $retval// return ACCEPT(1) or REJECT(0) 

    with Regards
    E Buddy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •