wesley tanaka

Django AdSense Site Authentication Support

Given that there might be some problems with AdSense cookie-based Site Authentication and Google App Engine, the easiest way to do AdSense Site Authentication with GAE seems to be using HTTP Basic access authentication.

This is a Django app which lets you grant AdSense access to your site using its Site Authentication feature.

Download

GitHub or Gitorious

Installation

Replace yourrandomkeyhere in these instructions with a randomly generated key of your choosing
  1. Copy the adsense_site_auth directory into your project
  2. In settings.py, add adsense_site_auth.middleware.AdSenseSiteAuthMiddleware to MIDDLEWARE_CLASSES and add a new line ADSENSE_SITEAUTH_PASSWORD='yourrandomkeyhere'
  3. In Site Authentication in your AdSense account, add a login with
    1. Authentication Method set to Plain Http (.htaccess)
    2. Attribute username set to AdSense
    3. Attribute password set to yourrandomkeyhere

Usage

In your web application's views, request.adsense_site_authenticated will be set to True if the request is coming from AdSense's bot.

Caveat

I have only tested this using Google App Engine Helper for Django and the stock Google App Engine Django 0.96.  Patches to fix problems in other environments/Django versions are greatly appreciated.

Feedback / Bug reports

Please give your feedback, report bugs or contribute patches on the Github project page.

Syndicate content