# AS3 OSMF & Secury Token

**URL:** <https://community.wowza.com/t/as3-osmf-secury-token/35532>\
**Category:** Wowza Streaming Engine\
**Created:** [September 23, 2010, 4:34pm UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532 "2010-09-23T16:34:03Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harley\_Cabral](https://avatars.discourse-cdn.com/v4/letter/h/439d5e/32.png) [@Harley\_Cabral](https://community.wowza.com/u/Harley_Cabral)\
**Post date:** [September 23, 2010, 4:34pm UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/1 "2010-09-23T16:34:03Z")

</div>

Hi

is it possible to use Flex OSMF and authenticate a stream with secury token ?

Im trying to use NetConnectionFactory to create a netConnection and handle its status to get a secury token, but i didnt find a way to do it…

in the old version of the app, with AS2, I used this code:

thisNc.call(“secureTokenResponse”, new Responder(onResult), TEA.decrypt(e.info.secureToken, myKey));

thisNc is a NetConnection.

but, how can I do it with AS3 osmf ?

I mean…

I is there a way to manipulate the NetConnection, or any other way to do this authentication ?

any help ?

tks a lot

[]'s

Harley

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [September 23, 2010, 8:10pm UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/2 "2010-09-23T20:10:27Z")

</div>

You will need the OSMF source code instead of the swc file. Then you can modify the onNetStatus function in NetLoader.as file, which is in the [org.osmf.net](http://org.osmf.net) package.

You can check out the source with svn here:

[http://opensource.adobe.com/svn/opensource/osmf](http://opensource.adobe.com/svn/opensource/osmf)

Then copy the org folder from here:

OSMF source framework\OSMF\org

To the Flash Builder project src folder

Then Delete the SWC file, modify the file and rebuild.

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [July 19, 2011, 12:26pm UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/3 "2011-07-19T12:26:26Z")

</div>

Below is source from a version of Wowza OSMF player that handles SecureToken and the Wowza Load Balancer NetConnection 302 redirect method, which are both things we decided not to include with the Wowza OSMF examples because the OSMF Wowza examples are more directed to Sanjose (Flash HTTP) streaming, but can of course do RTMP as well.

```auto
Removed

```

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [July 19, 2011, 12:27pm UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/4 "2011-07-19T12:27:22Z")

</div>

You can get com.wowza.encryptionAS3.TEA from any of the Wowza Flash examples.

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [July 20, 2011, 11:44am UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/5 "2011-07-20T11:44:39Z")

</div>

I will do some tests today.

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [July 25, 2011, 2:00pm UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/6 "2011-07-25T14:00:40Z")

</div>

I’ve been working on it. The source I posted was a bit mangled. I have it clearing the NetConnection NetStatusEvent handler, and handling the SecureToken, but haven’t quite got the RTMP playback re-constituted.

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [July 27, 2011, 6:43pm UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/7 "2011-07-27T18:43:54Z")

</div>

Turns out I was looking on the wrong machine. I updated the earlier post above with a player that uses OSMF framework, plays RTMP and handles SecureToken and 302 redirect.

However, Sanjose streams don’t work. Frankly, I’m not sure this qualifies as a OSMF player. It uses the OSMF framework then works around it really, and evidently breaks a key feature: Sanjose HTTP streaming. But take a look for what it’s worth. I might not leave it up.

Richard

---

<div class="post-metadata">

**Author:** ![Richard\_Lanham](https://avatars.discourse-cdn.com/v4/letter/r/c68b51/32.png) [@Richard\_Lanham](https://community.wowza.com/u/Richard_Lanham)\
**Post date:** [August 1, 2011, 7:53pm UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/8 "2011-08-01T19:53:05Z")

</div>

In my tests, it does plays RTMP and runs NetConnection NetStatusEvent, but it’s not a good example. Thanks for reminding me, I removed it again. I really just don’t know how to bring SecureToken functionality as it exists now into OSMF framework.

Richard

---

<div class="post-metadata">

**Author:** ![Harley\_Cabral](https://avatars.discourse-cdn.com/v4/letter/h/439d5e/32.png) [@Harley\_Cabral](https://community.wowza.com/u/Harley_Cabral)\
**Post date:** [September 23, 2010, 5:54pm UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/9 "2010-09-23T17:54:58Z")

</div>

tks a lot for your reply

now that you mentioned it, Im quitting using osmf, lol

tks bro!

[]'s

Harley

---

<div class="post-metadata">

**Author:** ![Jan-Michael\_Tholken](https://avatars.discourse-cdn.com/v4/letter/j/f05b48/32.png) [@Jan-Michael\_Tholken](https://community.wowza.com/u/Jan-Michael_Tholken)\
**Post date:** [March 24, 2012, 7:04pm UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/10 "2012-03-24T19:04:13Z")

</div>

> In my tests, it does plays RTMP and runs NetConnection NetStatusEvent, but it’s not a good example. Thanks for reminding me, I removed it again. I really just don’t know how to bring SecureToken functionality as it exists now into OSMF framework.
> 
> Richard

If anybody is interested in using OSMF 1.6 with Wowza SecureToken write me a message. I got it working a couple of weeks ago.

---

<div class="post-metadata">

**Author:** ![Jan-Michael\_Tholken](https://avatars.discourse-cdn.com/v4/letter/j/f05b48/32.png) [@Jan-Michael\_Tholken](https://community.wowza.com/u/Jan-Michael_Tholken)\
**Post date:** [March 26, 2012, 4:30pm UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/11 "2012-03-26T16:30:39Z")

</div>

> If anybody is interested in using OSMF 1.6 with Wowza SecureToken write me a message. I got it working a couple of weeks ago.

Give me a day or two to get the things together.

---

<div class="post-metadata">

**Author:** ![Jan-Michael\_Tholken](https://avatars.discourse-cdn.com/v4/letter/j/f05b48/32.png) [@Jan-Michael\_Tholken](https://community.wowza.com/u/Jan-Michael_Tholken)\
**Post date:** [April 14, 2012, 5:51pm UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/12 "2012-04-14T17:51:33Z")

</div>

Here are the changes I’ve made to get it working with OSMF 1.6.1 (should be easy to get this working on OSMF 2.0 too):

- add the TEA encryption library from wowza to the sourcecode

- at the top of org/osmf/net/NetNegotiator.as include the TEA.as -\>

```auto
import com.wowza.encryptionAS3.TEA;

```

- change the following at NetNegotiator.as in the function “onNetStatus”:

```auto
				case NetConnectionCodes.CONNECT_SUCCESS:
				
					// #### ADD THIS #####
					if(event.info.secureToken != null)
						NetConnection(event.target).call("secureTokenResponse", null, TEA.decrypt(event.info.secureToken, "SECURE_TOKEN"));					
					// #### END #####
					
					if (	event.info.hasOwnProperty("data")
						&& event.info.data.hasOwnProperty("version")
					   )
					{
						// Decorate the resource with the FMS version, as it may be useful downstream.
						resource.addMetadataValue(MetadataNamespaces.FMS_SERVER_VERSION_METADATA, event.info.data.version);
							
						CONFIG::LOGGING
						{
							logger.info("FMS Version: " + event.info.data.version);
						}
					}
					else
					{
						CONFIG::LOGGING
						{
							logger.info("FMS Version unknown");
						}
					}

```

that’s it.

---

<div class="post-metadata">

**Author:** ![Jan-Michael\_Tholken](https://avatars.discourse-cdn.com/v4/letter/j/f05b48/32.png) [@Jan-Michael\_Tholken](https://community.wowza.com/u/Jan-Michael_Tholken)\
**Post date:** [April 14, 2012, 6:01pm UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/13 "2012-04-14T18:01:36Z")

</div>

Here are my changes packaged in a zip files:

[http://funkdoobiest.de/wowza\_osmf\_securetoken.zip](http://funkdoobiest.de/wowza_osmf_securetoken.zip)

changes are marked with “HERE” in the source code.

---

<div class="post-metadata">

**Author:** ![Adam\_M](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@Adam\_M](https://community.wowza.com/u/Adam_M)\
**Post date:** [July 18, 2011, 2:58pm UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/14 "2011-07-18T14:58:15Z")

</div>

Hi

I tried to modify the NetLoader.as file in OSMF v1.5 stable but I’m still not having any luck.

I used the following code block in the onNetStatus function in the case NetConnectionCodes.CONNECT\_SUCCESS:

if (event.info.secureToken != null) {netConnection.call(“secureTokenResponse”, null, TEA.decrypt(event.info.secureToken, “#ed%h0#w@1”));}

However, I’m still getting the same result as if it wasn’t there at all. I also checked the OSMF example that ships with Wowza but it doesn’t look like that uses secureToken. I’m by no means a master developer. Are there any other suggestions on how to get this to work?

Thanks

---

<div class="post-metadata">

**Author:** ![Adam\_M](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@Adam\_M](https://community.wowza.com/u/Adam_M)\
**Post date:** [July 19, 2011, 8:31am UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/15 "2011-07-19T08:31:24Z")

</div>

Hi Richard, thanks for the code snippet. I am using secureToken and enforcing RTMPe only to protect our stream.

It looks like the secureToken is working, but I still receive the same error with your code. The trace on the client side looks like this:

testVersion: MAC 10,3,181,26\>=10,1,0,0: true

secureTokenResponse: true

event.traitType: audio

event.traitType: buffer

event.traitType: time

event.traitType: displayObject

event.playState: playing

event.traitType: play

infoObj.info.code: NetConnection.Connect.Closed

event.time: NaN

player.duration: NaN

event.time: NaN

player.duration: NaN

event.time: NaN

player.duration: NaN

Error: Error #2154: The NetStream Object is invalid. This may be due to a failed NetConnection.

at [flash.net](http://flash.net)::NetStream/play2()

at [org.osmf.net](http://org.osmf.net)::NetLoader/reconnectStream()[/Users/rashad/Documents/Adobe Flash Builder 4/WowzaSample/src/org/osmf/net/NetLoader.as:409]

at Function/org.osmf.net:NetLoader/private:setupStreamReconnect/org.osmf.net:onNetStatus()[/Users/rashad/Documents/Adobe Flash Builder 4/WowzaSample/src/org/osmf/net/NetLoader.as:616]

On the server side, the trace is:

INFO session connect-pending 127.0.0.1 -

INFO session connect 127.0.0.1 -

ERROR session comment 1302063160 ModuleSecureToken.onConnect: Action before response received: kill connection: clientId:1302063160

It seems like something that was happening in this thread:

[https://www.wowza.com/forums/showthread.php?575-secure-token-failure](https://www.wowza.com/forums/showthread.php?575-secure-token-failure)

Obviously the code you’ve given me works so I’m messing something up here. I followed the instructions to setup the server-side security module and made no special changes. The only change I made to the code snippet was to set the rtmpURL to connectURL directly instead of doing the replace functions to preserve the rtmp. Have you ever tried using this code with RTMP?

For reference, I’m using:

Flex SDK 4.1

OSMF 1.5

Wowza 2.2.4

Thanks.

---

<div class="post-metadata">

**Author:** ![Adam\_M](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@Adam\_M](https://community.wowza.com/u/Adam_M)\
**Post date:** [July 25, 2011, 5:00am UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/16 "2011-07-25T05:00:06Z")

</div>

Yes, I did use the OSMF v1.5 source and not the swc. Does anyone have any examples of OSMF and Wowza secureToken?

---

<div class="post-metadata">

**Author:** ![Adam\_M](https://avatars.discourse-cdn.com/v4/letter/a/f475e1/32.png) [@Adam\_M](https://community.wowza.com/u/Adam_M)\
**Post date:** [August 1, 2011, 11:45am UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/17 "2011-08-01T11:45:54Z")

</div>

Unfortunately, the code still produces the exact same result. Actually, the code looks fairly similar to the snippet that was posted before. Are you sure it was successfully switched out?

Again, I always assume I’m doing something wrong but I did try to clear my browser cache in case. Maybe the version of OSMF that I’m using is newer (1.5)? What .swc version did you use to get that code to work? Or did you use the latest source?

I would love to get this last issue resolved and switch my secure content to Wowza as well.

Thanks

---

<div class="post-metadata">

**Author:** ![sreenath\_pktr](https://avatars.discourse-cdn.com/v4/letter/s/0ea827/32.png) [@sreenath\_pktr](https://community.wowza.com/u/sreenath_pktr)\
**Post date:** [July 23, 2011, 2:09am UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/18 "2011-07-23T02:09:31Z")

</div>

I think You will need the OSMF source code instead of the swc file.

---

<div class="post-metadata">

**Author:** ![aravindakumar\_thanga](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@aravindakumar\_thanga](https://community.wowza.com/u/aravindakumar_thanga)\
**Post date:** [April 5, 2012, 11:04am UTC](https://community.wowza.com/t/as3-osmf-secury-token/35532/19 "2012-04-05T11:04:21Z")

</div>

Hi,

How to do the securetoken in OSMF player?please guide me.if u have a sample please send me it’s very helpful to me

Thanks,

AravindakumarThangaraju

> If anybody is interested in using OSMF 1.6 with Wowza SecureToken write me a message. I got it working a couple of weeks ago.
