Forums / Developer / REST API

REST API

Author Message

B Pierre

Friday 17 June 2011 2:53:48 am

Hi,

I try to do a REST API but i have a problem... I used this documentation : http://share.ez.no/learn/ez-publish/extending-ez-publish-s-rest-api-developer-preview-2, http://doc.ez.no/eZ-Publish/Technical-manual/4.5/Features/Rest-API.

 

Problem is : when i try to access a ressource i have an error message :

http://xxx.xxx.xxx.xxxx/api/ezp/content/node/63

"No Authorization header found"

 

This is my virtual host config :

"
 NameVirtualHost xxx.xxx.xxx.xxx

<VirtualHost *:80>

    DocumentRoot /ezFolder
    ServerName xxx.xxx.xxx.xxx
    ServerAlias xxx.xxx.xxx.xxx

    <Directory  /ezFolder>
        Options FollowSymLinks
        AllowOverride None
    </Directory>

    <IfModule mod_php5.c>
        php_admin_flag safe_mode Off
        php_admin_value register_globals 0
        php_value magic_quotes_gpc 0
        php_value magic_quotes_runtime 0
        php_value allow_call_time_pass_reference 0
    </IfModule>

    DirectoryIndex index.php

    # Rewrite rules to enable virtual host mode of eZ Publish
    # Secures eZ Publish by making sure only certain folders is accessible directly
    <IfModule mod_rewrite.c>
        RewriteEngine On
        # REST API
        RewriteRule ^/api/ /index_rest\.php [L]
        
        RewriteRule ^/([^/]+/)?content/treemenu.* /index_treemenu\.php [L]
        RewriteRule ^/var/([^/]+/)?storage/images(-versioned)?/.* - [L]
        RewriteRule ^/var/([^/]+/)?cache/(texttoimage|public)/.* - [L]
        RewriteRule ^/design/[^/]+/(stylesheets|images|javascript)/.* - [L]
        RewriteRule ^/share/icons/.* - [L]
        RewriteRule ^/extension/[^/]+/design/[^/]+/(stylesheets|flash|images|lib|javascripts?)/.* - [L]
        RewriteRule ^/packages/styles/.+/(stylesheets|images|javascript)/[^/]+/.* - [L]
        RewriteRule ^/packages/styles/.+/thumbnail/.* - [L]
        RewriteRule ^/var/storage/packages/.* - [L]

        # Makes it possible to placed your favicon at the root of your
        # eZ Publish instance. It will then be served directly.
        RewriteRule ^/favicon\.ico - [L]
        # Uncomment the line below if you want you favicon be served from the standard design.
        # You can customize the path to favicon.ico by replacing design/standard/images/favicon.ico
        # by the adequate path.
        #RewriteRule ^/favicon\.ico /design/standard/images/favicon\.ico [L]
        RewriteRule ^/design/standard/images/favicon\.ico - [L]

        # Give direct access to robots.txt for use by crawlers (Google, Bing, Spammers..)
        RewriteRule ^/robots\.txt - [L]

        # Platform for Privacy Preferences Project ( P3P ) related files for Internet Explorer
        # More info here : http://en.wikipedia.org/wiki/P3p
        RewriteRule ^/w3c/p3p\.xml - [L]

        # Uncomment the following lines when using popup style debug.
        # RewriteRule ^/var/cache/debug\.html.* - [L]
        # RewriteRule ^/var/[^/]+/cache/debug\.html.* - [L]

        RewriteRule .* /index\.php
    </IfModule>

    # Everything below is optional to improve performance by forcing clients to cache
    # image and design files, change the expires time to suite project needs.
    <IfModule mod_expires.c>
        <LocationMatch "^/var/[^/]+/storage/images/.*">
        # eZ Publish appends the version number to image URL (ezimage datatype)
        # so when an image is updated, its URL changes to
            ExpiresActive on
            ExpiresDefault "now plus 10 years"
        </LocationMatch>

        <LocationMatch "^/extension/[^/]+/design/[^/]+/(stylesheets|images|javascripts?|flash)/.*">
        # A good optimization if you normally don't change your design often
            ExpiresActive on
            ExpiresDefault "now plus 5 days"
        </LocationMatch>

        <LocationMatch "^/extension/[^/]+/design/[^/]+/lib/.*">
        # Libraries get a new url (version number) on updates
            ExpiresActive on
            ExpiresDefault "now plus 90 days"
        </LocationMatch>

        <LocationMatch "^/design/[^/]+/(stylesheets|images|javascripts?|lib|flash)/.*">
        # Same as above for bundled eZ Publish designs
            ExpiresActive on
            ExpiresDefault "now plus 7 days"
        </LocationMatch>

        <LocationMatch "^/share/icons/.*">
        # Icons as used by admin interface, barly change
            ExpiresActive on
            ExpiresDefault "now plus 7 days"
        </LocationMatch>

        # Depends on ezjscore.ini/[Packer]/AppendLastModifiedTime=enabled
        # so that file names change when source files are modified
        #<LocationMatch "^/var/[^/]+/cache/public/.*">
        # Force ezjscore packer js/css files to be cached 30 days at client side
            #ExpiresActive on
            #ExpiresDefault "now plus 30 days"
        #</LocationMatch>
    </IfModule>
</VirtualHost>

This is my rest.ini.append.php config :

 <?php
#?ini charset="utf-8"?

[System]
PrefixFilterClass=ezpRestDefaultRegexpPrefixFilter
ApiPrefix=/api

[ApiProvider]
ProviderClass[]

[DebugSettings]
Debug=enabled

[OutputSettings]
RendererClass[xhtml]=ezpContentXHTMLRenderer

[ezpRestContentController_viewContent_OutputSettings]
Template=rest_pagelayout.tpl

[CacheSettings]
ApplicationCache=enabled
ApplicationCacheDefault=enabled
DefaultCacheTTL=600
RouteApcCache=enabled
RouteApcCacheTTL=3600

[Authentication]
RequireAuthentication=disabled
AuthenticationStyle=ezpRestOauthAuthenticationStyle
#AuthenticationStyle=ezpRestBasicAuthStyle
RequireHTTPS=disabled

[RouteSettings]
RouteSettingImpl=ezpRestIniRouteFilter

SkipFilter[]
SkipFilter[]=ezpRestErrorController_show
SkipFilter[]=ezpRestAuthController_basicAuth
SkipFilter[]=ezpRestAuthController_oauthRequired
SkipFilter[]=ezpRestOauthTokenController_handleRequest
SkipFilter[]=myController_*;2

# RunFilter[]

[PreRoutingFilters]
Filters[]

[RequestFilters]
Filters[]

[ResultFilters]
Filters[]

[ResponseFilters]
Filters[]
?>
"

And my oauth :

     Nom:New REST application
     Description:Test REST
     Client identifier:3720b653cea47bcd09b0f2a38524c661
     Client secret:2837d9104863438aeba7eb1533ea621d
     Endpoint URI:http://xxx.xxx.xxx.xxx

 

But i think it's not necessary because i have disable the authentication.

Where i'm wrong ?

 

Thanks for your answers

Thiago Campos Viana

Saturday 18 June 2011 1:06:04 pm

Hi

I get it working, please follow the instructions on this post, also check my blog post about using basic http auth (or no auth) with jquery.

eZ Publish Certified Developer: http://auth.ez.no/certification/verify/376924

Twitter: http://twitter.com/tcv_br