Adobe Flex 3 Help

Using the DRMAuthenticateEvent class

The DRMAuthenticateEvent object is responsible for gathering the user credentials (i.e. user name, password, and type) and passing the values to the NetStream.setDRMAuthenticationCredentials() method for validation. Each AIR application is responsible for providing some mechanism for retrieving the user's authentication credentials. For example, the application could provide a user with a simple user interface to enter the username and password values, and optionally the type value as well.

Contents

DRMAuthenticateEvent properties

The DRMAuthenticateEvent class includes the following properties:

Property

Description

authenticationType

Indicates whether the supplied credentials are for authentication against the DRM credentials list, or, if the content is stored on a proxy server, against the credentials list for the proxy server.

header

The encrypted content file header provided by the server.

originater

The NetStream object that initiated this event.

passwordPrompt

A prompt for a password credential, provided by the server. You can use this property to provide application users with the context of why they need to provide a password when seeking authentication credentials.

 

urlPrompt

A prompt for a URL to display, provided by the server. You can use this property to provide application users with the context of which URL they are attempting to view when seeking authentication credentials.

usernamePrompt

A prompt for a user name credential, provided by the server. You can use this property to provide application users with the context of why they need to provide a user name when seeking authentication credentials.

Creating a DRMAuthenticateEvent handler

The following example creates an event handler that passes a set of hard-coded authentication credentials to the NetStream object that originated the event. Add this event handler to a NetStream object that points to DRM-encrypted content.

ActionScript example:

private function drmAuthenticateEventHandler(event:DRMAuthenticateEvent):void 
{
    videoStream.setDRMAuthenticationCredentials("administrator", "password", "drm");
}

Creating an interface for retrieving user credentials

In the case where DRM content requires user authentication, the AIR application will usually need to retrieve the user's authentication credentials via a user interface.

The following is a Flex example of a simple user interface for retrieving user credentials. It consists of a panel object containing two TextInput objects, one for each of the user name and password credentials. The panel also contains a button that launches the credentials() method.

<mx:Panel x="236.5" y="113" width="325" height="204" layout="absolute" title="Login">
    <mx:TextInput x="110" y="46" id="uName"/>
    <mx:TextInput x="110" y="76" id="pWord" displayAsPassword="true"/>
    <mx:Text x="35" y="48" text="Username:"/>
    <mx:Text x="35" y="78" text="Password:"/>
    <mx:Button x="120" y="115" label="Login" click="credentials()"/>
</mx:Panel>

The credentials() method is a user-defined method that passes the user name and password values gathered in the simple user interface to the setDRMAuthenticationCredentials() method. Once the values are passed, the credentials() method resets the values of the TextInput objects.

<mx:Script>
    <![CDATA[
        public function credentials():void 
        {
            video.setDRMAuthenticationCredentials(uName, pWord, "drm");
            uName.text = "";
            pWord.text = "";
        }
    ]]>
</mx:Script>

One way to implement this type of simple interface is to include the panel as part of a new state that originates from the base state when the DRMAuthenticateEvent object is thrown. The following example contains a VideoDisplay object with a source attribute that points to a DRM-protected FLV. IN this case, the credentials() method is modified so that it also returns the application to the base state after passing the user credentials and resetting the TextInput object values.

<?xml version="1.0" encoding="utf-8"?>
<mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="absolute"
    width="800"
    height="500"
    title="DRM FLV Player"
    creationComplete="initApp()" >

    <mx:states>
        <mx:State name="LOGIN">
            <mx:AddChild position="lastChild">
                <mx:Panel x="236.5" y="113" width="325" height="204" layout="absolute" title="Login">
                    <mx:TextInput x="110" y="46" id="uName"/>
                    <mx:TextInput x="110" y="76" id="pWord" displayAsPassword="true"/>
                    <mx:Text x="35" y="48" text="Username:"/>
                    <mx:Text x="35" y="78" text="Password:"/>
                    <mx:Button x="120" y="115" label="Login" click="credentials()"/>
                    <mx:Button x="193" y="115" label="Reset" click="uName.text='';pWord.text='';"/>
                </mx:Panel>
            </mx:AddChild>
        </mx:State>
    </mx:states>

    <mx:Script>
        <![CDATA[
             import flash.events.DRMAuthenticateEvent;
            private function initApp():void 
            {
                video.addEventListener(DRMAuthenticateEvent.DRM_AUTHENTICATE, drmAuthenticateEventHandler);
            }

            public function credentials():void 
            {
                video.setDRMAuthenticationCredentials(uName, pWord, "drm");
                uName.text = "";
                pWord.text = "";
                currentState='';
            }

            private function drmAuthenticateEventHandler(event:DRMAuthenticateEvent):void 
            {
                currentState='LOGIN';
            }
        ]]>
    </mx:Script>
    
    <mx:VideoDisplay id="video" x="50" y="25" width="700" height="350"
        autoPlay="true"
        bufferTime="10.0"
        source="http://www.example.com/flv/Video.flv" />
</mx:WindowedApplication>