<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type='text/xsl' href='./OpenSocial.xslt' ?>
<?rfc toc="yes"?>
<!DOCTYPE rfc PUBLIC "-//IETF//DTD RFC 2629//EN" "http://xml.resource.org/authoring/rfc2629.dtd">
<rfc ipr="full3978"
     docName="opensocial-mobile-extension-specification-draft"
     xmlns:x="http://purl.org/net/xml2rfc/ext">
  <front>
    <title abbrev="Mobile-Extension">OpenSocial Mobile Extension Specification (draft)</title>
    <author fullname="Yoichiro Tanaka (mixi, Inc)">
      <address>
        <email>yoichiro.tanaka@mixi.co.jp</email>
      </address>
    </author>
    <author fullname="Hidetaka Yamashita (mixi, Inc)">
      <address>
        <email>hidetaka.yamashita@mixi.co.jp</email>
      </address>
    </author>
    <date month="November"
          year="2010" />
    <area>Mobile</area>
    <keyword>OpenSocial</keyword>
    <keyword>social networking</keyword>
    <keyword>REST</keyword>
    <keyword>XML</keyword>
    <keyword>Extensible Markup Language</keyword>
    <keyword>JSON</keyword>
    <keyword>JavaScript Object Notation</keyword>
    <keyword>Atom</keyword>
  </front>
  <middle>
    <section title="Notation and Conventions">
      <t>Keywords such as, "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
        "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" used in this
        document are to be interpreted as described in
        <xref target="RFC2119">RFC2119</xref>.</t>
      <t>Domain name examples use <xref target="RFC2606">RFC2606</xref>.</t>
    </section>
    <section title="Overview">
      <t>In OpenSocial specification version 1.0, JavaScript APIs for developing applications that run on Web browsers are provided. These APIs are available only if JavaScript codes are supported. However, most Web browsers available on cell-phones based on WAP currently do not support JavaScript and an iframe tag. Many people access the Internet from their cell-phones and use social networking services. There are even countries where access to the Internet is seen more from cell-phones than from PCs. In order for social applications to further develop, we CANNOT ignore support to cell-phones based on WAP.</t>
      <t>OpenSocial Mobile Extension specification is a profile for cell-phones which do not support JavaScript codes. An application developed by this profile uses an OpenSocial RESTful API to retrieve the social graph of a SNS. This document describes an architecture and features commonly provided in OpenSocial Mobile Extension. SNS that want to provide a social application for cell-phones SHOULD support features described in this profile.</t>
    </section>
    <section title="Compliance">
      <t>In order to become a compliant Application Container, a server MUST be able to satisfy the requests defined in this section.</t>
      <section title="Process flow">
        <t>For a better understanding this process flow is introduced below.</t>
        <figure>
            <preamble>Process flow:</preamble>
            <artwork xml:space="preserve">
[cell-phone]   [application container]   [external server]
      |                   | Retrieve Start URL -&gt; |
      | Accept Request -&gt; |                       |
      |                   |   Forward Request -&gt;  |
      |                   |  &lt;- Receive Response  |
      | &lt;- Response Page  |                       |
            </artwork>
          </figure>
      </section>
      <section title="Retrieve Start URL Request">
        <t>Application Containers MUST be able to fetch a gadget spec file, and MUST be able to retrieve a Start URL written in the file.</t>
        <t>Gadget spec file SHOULD be retrieved from the URL provided to the Container by the developer. Application Containers MUST parse the retrieved gadget XML file, and MUST get the Start URL written in the file. This Start URL is the destination of the first request sent when users launch an application.</t>
	<t>The view for WAP-phone device in this profile has the content type "wap". Application Container finds the Content element which has the "wap" value as the value of the attribute "type". The Start URL is written as the value of the href attribute. Generally, Application Container will download the Gaget spec file when the developer registers the application and Application Container retrieves the Start URL from the Gadget spec file at same time.</t>
      </section>
      <section title="Accept Request">
        <t>Application Containers MUST be able to accept requests from the cell-phone, and MUST be able to verify the content and also add necessary information.</t>
        <t>Basically, all requests from an application running on a cell-phone SHOULD be processed by the application container. The content of the request accepted by the Container SOULD be verified, and Application Container SHOULD remove unnecessary information from the request. And, information of the user who activated the application and the application's ID MUST be added to the request by the Application Container.</t>
	<t>For example, there is a case that some IDs or identifiers which can specify the individual and should not send them to the application developer is sent from the cell-phone to the application container. In this case, the application container needs to remove these information from the request. If these information is sent to the application developer, it may be told a information leaking.</t>
	<t>Application Container MUST add information of the user to the request so that the application has a capability of a social. The application developer can know who do use the application by retrieving the user ID included the request.</t>
      </section>
      <section title="Forward Request">
        <t>Application Containers MUST be able to forward verified requests to an external server of the developer used for building contents.</t>
        <t>If a request includes a URL parameter, the application container will forward the request to the server specified in the URL parameter. Also, if the request does not include a URL parameter, the application container will forward the request to the Start URL. At this timing, user information and the application ID added during the previous phase are sent to the server. In order for the developer's server to be able to verify whether the request is valid or not, the application container SHOULD have a signature in the request.</t>
      </section>
      <section title="Receive Response">
        <t>Application Container MUST be able to receive a response including content built by the developer's external server.</t>
        <t>The received contents will be validated and transformed by the application container. For example, the application container MAY add a header and footer to the content. In addition, the application container MAY replace the URL written in the contents, such as of an image, and MAY remove invalid codes (JavaScript code and etc). Furthermore, in order to allow usage of functions with a user flow specific codes SHOULD be replaced by the application container during this phase.</t>
        <t>The response time from the developer's external server may severely delay. Application Container MAY limit the available length of response time. If the response is not received within the valid period of time, the application container will display the error page to the user.</t>
      </section>
      <section title="Response Page">
        <t>The application container MUST send the fixed page to the user's cellphone.</t>
        <t>The page which has been fixed during the previous phase is then sent from the application container to the user's cell-phone. The user will take a new action from the displayed page. As a result of this action, a new request is then sent to the application container.</t>
      </section>
    </section>
    <section title="Gadget Spec file">
      <t>This section describes the specification of Gadget Spec file of social applications for cell-phones.</t>
      <section title="View for cell-phone">
        <t>In this specification, a special view is defined for social applications for the cell-phones. The view type is called "wap". This view is defined using a Content element in the Gadget spec file. Thus, this definition is the same with the definition of Gadgets for PC.</t>
        <t>The "wap" is specified as the attribute value of the Content element type. And, the Start URL is specified as the "href" attribute value. The Content element may not contain a body, since the server specified by the Start URL will generate the contents.</t>
      </section>
      <section title="Example">
        <t>
          <figure>
            <artwork xml:space="preserve">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;Module&gt;
  &lt;ModulePrefs title="App for Cell-phone"&gt;
  &lt;/ModulePrefs&gt;
  &lt;Content view="any" type="wap" href="http://start.url/" /&gt;
&lt;/Module&gt;
            </artwork>
          </figure>
        </t>
      </section>
      <section title="Coexistence">
        <t>The view for cell-phones can co-exist with other views. At the same time, multiple Content elements holding other view attributes can be written in the Gadget spec file.</t>
        <t>
          <figure>
            <preamble>The following code is the example to have two Content elements:</preamble>
            <artwork xml:space="preserve">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;Module&gt;
  &lt;ModulePrefs title="App for Cell-phone"&gt;
  &lt;/ModulePrefs&gt;
  &lt;Content view="mobile" type="wap" href="http://start.url/" /&gt;
  &lt;Content view="canvas" type="html"&gt;&lt;[CDATA[
    &lt;div&gt;Hello, world!&lt;/div&gt;
  ]]&gt;&lt;/Content&gt;
&lt;/Module&gt;
            </artwork>
          </figure>
        </t>
      </section>
      <section title="Data Pipelining and Proxied Content">
        <t>This wap extension supports the Data Pipelining and Proxied Context. For instance, the content element which has the "wap" type can have some tags using Data Pipelining to provide the viewer, owner and the friends information for the external server. The sample code is like following:</t>
        <figure>
            <artwork xml:space="preserve">
&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;Module&gt;
  &lt;ModulePrefs title="App for Cell-phone"&gt;
    ...
  &lt;/ModulePrefs&gt;
  &lt;Content view="any" type="wap" href="http://start.url/"&gt;
    &lt;os:PeopleRequest key="vf" userid="@viewer" groupid="@friends" /&gt;
  &lt;/Content&gt;
&lt;/Module&gt;
            </artwork>
        </figure>
        <t>The results of the data pipelining requests will be sent to the href of the &lt;Content&gt; section as POSTed JSON data. These information will be used by the external server to render the social data.</t>
      </section>
    </section>
    <section title="Request and Response">
      <t>This section describes the request sent from the application container and the expected response.</t>
      <section title="Request">
        <t>The content of the request and the conditions to determin which target server to send requests by the application container are described here.</t>
        <section title="Forwarding target">
          <t>When the application container receives a request from the cell-phone, the target to forward to will differ depending on the condition. In other words, it is decided based on whether a url parameter is included or not in the request. The condition is described in the following:</t>
          <texttable align="left">
            <ttcol>Request URL example</ttcol>
            <ttcol>Include url parameter?</ttcol>
            <ttcol>Forwarding target</ttcol>
            <c>http://application.container/app_id</c>
            <c>No</c>
            <c>Start URL written on Gadget Spec file.</c>
            <c>http://application.container/gadgets/ifr?url=http%3A%2F%2Fexternal.server%2gadget.xml&amp;st=abcdefg&amp;...</c>
            <c>No</c>
            <c>Start URL written on Gadget Spec file specified by the url parameter included in the query parameters.</c>
            <c>http://application.container/app_id?url=http%3A%2F%2Fexternal.server%2Fpath1%2Fpath2</c>
            <c>Yes</c>
            <c>http://external.server/path1/path2</c>
          </texttable>
        </section>
        <section title="Request patameters">
          <t>The request sent from the cell-phone will be forwarded to the external server of the developer (Forward Request). The application container will add several parameters to the request, when forwarding the request. The purpose to add these parameters is to add socialness to the application.</t>
          <t>The parameters generally often added are the following:</t>
          <texttable align="left">
            <ttcol>Name</ttcol>
            <ttcol>Type</ttcol>
            <ttcol>Description</ttcol>
            <ttcol>Required</ttcol>
            <c>opensocial_owner_id</c>
            <c>Query parameter</c>
            <c>The ID of the user who owns the application accessed by the viewer.</c>
            <c>Yes</c>
            <c>opensocial_app_id</c>
            <c>Query parameter</c>
            <c>The ID of the application which the user is currently using.</c>
            <c>Yes</c>
            <c>opensocial_viewer_id</c>
            <c>Query parameter</c>
            <c>The ID of the user who is currently accessing to the application.</c>
            <c>Optional</c>
            <c>User-Agent</c>
            <c>Request Header</c>
            <c>The identifier to specify the device of the user.</c>
            <c>Yes</c>
            <c>X-Forwarded-For</c>
            <c>Request Header</c>
            <c>The IP address of the access origin.</c>
            <c>Optional</c>
          </texttable>
          <t>The application developer can generate suitable contents for the device the user is  using by referencing the User-Agent request header.</t>
          <t>In addition, the application container MAY remove several parameters included in the request received request from the cell-phone. At times the request may include privacy information in addition to ID used within the SNS to identify an individual. Such information SHOULD be removed by the application container to protect the user's privacy.</t>
          <t>If the Data pipelining is used in the Content element, the social data will be sent with the above parameters as JSON format included the POST body.</t>
        </section>
      </section>
      <section title="Response">
        <t>The application container expects to receive XHTML content responses. The format must be parseable by the application container. If the application container cannot parse the contents in XHTML format, the application container will return an error to the external server which generated the contents.</t>
        <t>The user's profile information retrieved from an OpenSocial RESTful API will be included in the contents of the external server. Also, the contents may change accordingly to the User-Agent parameter included in the request.</t>
        <t>Parts of the contents will be replaced by the application container. The purpose is to support User Flow functions and to replace the url parameter.</t>
        <section title="Replacing URLs">
          <t>To assure that the request from the cell-phone always get through the application container, the application container MUST replace URLs written in the content generated by the external server. The tags for navigating pages (i.e. a tag and form tag) are the target tags of such replacement.</t>
          <t>Application developers can write the specific URL they wish to retrieve on the external server as the value of the href or action attribute. For example, the URL is replaced simillar to the following.</t>
          <t>Before:</t>
          <figure>
            <artwork xml:space="preserve">
&lt;a href="http://external.server/path1/path2"&gt;Click!&lt;/a&gt;

&lt;form action="http://external.server/path1/path2"&gt;
  ...
&lt;/form&gt;
            </artwork>
          </figure>
          <t>After:</t>
          <figure>
            <artwork xml:space="preserve">
&lt;a href="http://application.container/app_id/?url=http%3A%2F%2Fexternal.server%2Fpath1%2Fpath2"&gt;Click!&lt;/a&gt;

&lt;form action="http://application.container/app_id/?url=http%3A%2F%2Fexternal.server%2Fpath1%2Fpath2"&gt;
  ...
&lt;/form&gt;
            </artwork>
          </figure>
        </section>
        <section title="User Flow functions">
          <t>With user flow functions, the specific URL schema written by the application developer will be replaced automatically to the complete URL by the application container. The purpose is to navigate the user to the page prepared by the application container. For example, when using the function to invite friends to an application, the URI schema will be replaced like the following.</t>
          <t>Before:</t>
          <figure>
            <artwork xml:space="preserve">
&lt;a href="invite:friend?callback=http%3A%2F%2Fexternal.server%2Fpath1%2Fpath2"&gt;Invite!&lt;/a&gt;
            </artwork>
          </figure>
          <t>After:</t>
          <figure>
            <artwork xml:space="preserve">
&lt;a href="http://application.container/invite/friend?callback=http%3A%2F%2Fexternal.server%2Fpath1%2Fpath2"&gt;Invite!&lt;/a&gt;
            </artwork>
          </figure>
        </section>
      </section>
    </section>
    <section title="Validation">
      <t>the application container will send a request to generate the contents to the external server. The external server must validate whether the sender of the request is the actual application container or not.</t>
      <t>Several methods to check the validness of the request exist. The most popular adopted method is the method of giving a signature to the request. The external server can validate the request by checking the signature added by the application container. HMAC-SHA1, RSA-SHA1 etc, can be applied as methods for generating a signature.</t>
      <t>An example on how to generate a signature with HMAC-SHA1 is introduced in the section, [Generating the signature with OAuth].</t>
    </section>
    <section title="User Flow functions">
      <t>The application container can provide functions with pages which the application container have already prepared. For example, if users want to invite friends to an application, the application container will navigate users to the page to select who to invite. After users finish selecting their friends, the application container will bring back users to the application's page. SUch function is called 'User Flow functions'.</t>
      <t>Commonly used User Flow functions have been standardized in this specification. In addition, the application container can define a container-specific User Flow function. The URI schema is defined for each User Flow function to navigate users to an already parepared page. The application container MUST replace the URI schema to the page's URL.</t>
      <section title="Format">
        <t>The application developer MUST use the User Flow function under the following format:</t>
        <figure>
          <artwork xml:space="preserve">
[URI-schema]?[parameter1=value1]&amp;[parameter2=value2]&amp;...
          </artwork>
        </figure>
        <t>The following format can also be used when using a form tag of HTML:</t>
        <figure>
          <artwork xml:space="preserve">
&lt;form action="[URI-schema]"&gt;
  &lt;input type="hidden" name="[parameter1]" value="[value1]" /&gt;
  &lt;input type="hidden" name="[parameter2]" value="[value2]" /&gt;
  ...
&lt;/form&gt;
          </artwork>
        </figure>
      </section>
      <section title="Required parameters">
        <t>The required parameters for all User Flow functions are the following:</t>
        <texttable align="left">
          <ttcol>Name</ttcol>
          <ttcol>Description</ttcol>
          <c>callback</c>
          <c>The URL of the redirecting target to go back after completing the User Flow function. This URL MUST be URI-escaped.</c>
        </texttable>
	<t>If the application container wants to return the result of the process to the application, the result value is added as the query parameter to the URL specified by the callback parameter.</t>
      </section>
      <section title="Standard functions">
	<t>In this section, specifications of commonly supported User Flow functions are described.</t>
	<section title="Invitation">
	  <t>URI schema: invite:friends</t>
	  <t>Description: The application container navigates users to the page where they can select friends they want to invite to the application.</t>
	  <t>Parameters:</t>
	  <texttable align="left">
	    <ttcol>Name</ttcol>
	    <ttcol>Type</ttcol>
	    <ttcol>Description</ttcol>
	    <c>callback</c>
	    <c>String</c>
	    <c>The target URL to return the user to the application after selecting friends by the user.</c>
	  </texttable>
	  <t>Result values:</t>
	  <texttable align="left">
	    <ttcol>Name</ttcol>
	    <ttcol>Type</ttcol>
	    <ttcol>Description</ttcol>
	    <c>invite_member</c>
	    <c>User IDs separated by commna.</c>
	    <c>The user's IDs which the user selected to invite.</c>
	  </texttable>
	  <t>Example:</t>
	  <figure>
	    <artwork xml:space="preserve">
Request:
  &lt;a href="invite:friends?callback=http%3A%2F%2Fexternal.server%2Fpath1%2Fpath2"&gt;Invite!&lt;/a&gt;

Redirecting target URL:
  http://external.server/path1/path2?invite_member=123,456,789
	    </artwork>
	  </figure>
	</section>
      </section>
    </section>
  </middle>
  <back>
    <references>
      <reference anchor="RFC2119">
        <front>
          <title>Key words for use in RFCs to Indicate Requirement Levels</title>
          <author initials="S."
                  surname="Bradner"
                  fullname="Scott Bradner">
            <organization abbrev="HarvardU">Harvard University</organization>
          </author>
          <date month="March"
                year="1997" />
        </front>
        <seriesInfo name="RFC"
                    value="2119" />
      </reference>
      <reference anchor="RFC2606">
        <front>
          <title>Reserved Top Level DNS Names</title>
          <author initials="D."
                  surname="Eastlake"
                  fullname="Donald E. Eastlake 3rd">
            <organization abbrev="IBM">IBM</organization>
          </author>
          <author initials="A."
                  surname="Panitz"
                  fullname="Aliza R. Panitz" />
          <date month="June"
                year="1999" />
        </front>
        <seriesInfo name="RFC"
                    value="2606" />
      </reference>
      <reference anchor="OAuth-Consumer-Request"
                 target="http://oauth.googlecode.com/svn/spec/ext/consumer_request/1.0/drafts/2/spec.html">
        <front>
          <title>Using OAuth for Consumer Request</title>
          <date month="September"
                year="2008" />
        </front>
      </reference>
    </references>
  </back>
</rfc>

