Unable to Create Application through REST API

Viewed 156

Normally we are able to play around with REST APIs related to application, since the application has method to let us create a JWT Token for authentication.

But we are unable to create an application, don’t understand where and we can get the token to authorize us to let us create an application.

1 Answers

Let me tell step by step how to do that

  1. Open the file {AMS_INSTALL_DIR}/webapps/root/WEB-INF/web.xml and change the following line

    <filter-class>io.antmedia.console.rest.AuthenticationFilter</filter-class>
    

    with this one

    <filter-class>io.antmedia.console.rest.JWTServerFilter</filter-class>
    
  2. Open the file {AMS_INSTALL_DIR}/conf/red5.properties and change the following lines

    server.jwtServerControlEnabled=false
    server.jwtServerSecretKey=
    

    with these ones. You can use any 32 character alphanumeric key.

    server.jwtServerControlEnabled=false
    server.jwtServerSecretKey=WRITE_YOUR_32_CHARACTER_SECRET_KEY
    

    For our sample we use cizvvh7f6ys0w3x0s1gzg6c2qzpk0gb9 as secret key

  3. Restart the service

    sudo service antmedia restart
    
  4. Generate JWT Token. There are plenty of libraries that you can do programmatically. The easiest way for now is using JWT Debugger. So our generated token is eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.tA6sZwz_MvD9Nocf3Xv_DXhJaeTNgfsHPlg3RHEoZRk

JWT Token Generated for Ant Media Server

  1. Make the call to Create Application as follows

    curl -X POST -H "Content-Type: application/json" -H "Authorization:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.tA6sZwz_MvD9Nocf3Xv_DXhJaeTNgfsHPlg3RHEoZRk" "https://ovh36.antmedia.io:5443/rest/v2/applications/testapp"
    

    The result should be something like {"success":true,"message":null,"dataId":null,"errorId":0}

The app should be generated in a couple of seconds. You can get the list of the applications with the following command

curl -X GET -H "Content-Type: application/json" -H "Authorization:eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.tA6sZwz_MvD9Nocf3Xv_DXhJaeTNgfsHPlg3RHEoZRk" "https://ovh36.antmedia.io:5443/rest/v2/applications"

References:

Related