<?xml version="1.0" encoding="utf-8"?>

<?xml-model href="rfc7992bis.rnc"?>
<!-- Required for schema validation and schema-aware editing -->
<!-- <?xml-stylesheet type="text/xsl" href="rfc2629.xslt" ?> -->
<!-- This third-party XSLT can be enabled for direct transformations in XML processors, including most browsers -->


<!DOCTYPE rfc [
  <!ENTITY nbsp    "&#160;">
  <!ENTITY zwsp   "&#8203;">
  <!ENTITY nbhy   "&#8209;">
  <!ENTITY wj     "&#8288;">
]>
<!-- If further character entities are required then they should be added to the DOCTYPE above.
     Use of an external entity file is not recommended. -->

<rfc
  xmlns:xi="http://www.w3.org/2001/XInclude"
  category="info"
  docName="draft-vattaparambil-oauth-poa-grant-type-01"
  ipr="trust200902"
  obsoletes=""
  updates=""
  submissionType="IETF"
  xml:lang="en"
  version="3">
<!-- [REPLACE] 
       * docName with name of your draft
     [CHECK] 
       * category should be one of std, bcp, info, exp, historic
       * ipr should be one of trust200902, noModificationTrust200902, noDerivativesTrust200902, pre5378Trust200902
       * updates can be an RFC number as NNNN
       * obsoletes can be an RFC number as NNNN 
-->

  <front>
    <title abbrev="Abbreviated Title">OAuth-PoA Grant Type</title>
    <!--  [REPLACE/DELETE] abbrev. The abbreviated title is required if the full title is longer than 39 characters -->

    <seriesInfo name="Internet-Draft" value="draft-vattaparambil-oauth-poa-grant-type-01"/>

    <author fullname="Sreelakshmi Vattaparambil Sudarsan" surname="Vattaparambil Sudarsan">
      <!-- [CHECK]
             * initials should not include an initial for the surname
             * role="editor" is optional -->
    <!-- Can have more than one author -->
      
    <!-- all of the following elements are optional -->
      <organization>Lulea University of Technology</organization>
      <address>
        <postal>
          <!-- Reorder these if your country does things differently -->
          <city>Lulea</city>
          <code>97187</code>
          <country>Sweden</country>
          <!-- Uses two letter country code -->
        </postal>        
        <email>srevat@ltu.se</email>
        <!-- Can have more than one <email> element -->
      </address>
    </author>

    <author fullname="Olov Schelen" surname="Schelen">
      <organization>Lulea University of Technology</organization>
      <address>
        <postal>
          <city>Lulea</city>
          <code>97187</code>
          <country>Sweden</country>
        </postal>
        <email>olov.schelen@ltu.se</email>
      </address>
    </author>

    <author fullname="Ulf Bodin" surname="Bodin">
      <organization>Lulea University of Technology</organization>
      <address>
        <postal>
          <city>Lulea</city>
          <code>97187</code>
          <country>Sweden</country>
        </postal>
        <email>ulf.bodin@ltu.se</email>
      </address>
    </author>
   
    <date year="2023"/>
    <!-- On draft subbmission:
         * If only the current year is specified, the current day and month will be used.
         * If the month and year are both specified and are the current ones, the current day will
           be used
         * If the year is not the current one, it is necessary to specify at least a month and day="1" will be used.
    -->

    <area>General</area>
    <workgroup>Internet Engineering Task Force</workgroup>
    <!-- "Internet Engineering Task Force" is fine for individual submissions.  If this element is 
          not present, the default is "Network Working Group", which is used by the RFC Editor as 
          a nod to the history of the RFC Series. -->

    <keyword>PoA based authorization</keyword>
    <keyword>OAuth</keyword>
    <!-- [REPLACE/DELETE]. Multiple allowed.  Keywords are incorporated into HTML output files for 
         use by search engines. -->

    <abstract>
      <t>This draft proposes a new grant type for OAuth based on PoA-based authorization, that introduces a new role "principal"
        who controls the client, and enables the client to access resources owned by the resource owner via OAuth authorization
        server, on behalf of the principal, even if the principal is not online.
      </t>
    </abstract>
 
  </front>

  <middle>
    
    <section>
      <name>Introduction</name>
      <t>This OAuth 2.0 <xref target="OAuth"/> protocol grant type extension makes the OAuth applicable in a scenario where a principal (e.g., a user)
        who controls the OAuth client delegates their
        power to the client which allows the client to access resources from the resource owner
        on behalf of the user. The subgranting of power from the principal to the
        client is made possible using the self-contained PoA-based authorization. PoA-based authorization is a generic authorization technique
        used to authorize devices to access protected resources on behalf of the principal (user). Here, the client includes autonomous/semi-autonomous
        devices with sufficient resources to take part in the authorization process. PoA adds the following critical properties to OAuth:
      </t>

      <ul>
        <li>The client can work on behalf of the principal, even if the principal is not online.</li>
        <li>A possible separation of the principal and the resource owner.</li>
        <li>The client can send the PoA to another client using the multi-level
          authorization feature of PoA-based authorization.</li>
      </ul>
      <t>For example, consider a scenario where a user is occupied with some other tasks and requires data/resources from a third-party web server (resource owner).
        The user who owns an autonomous/semi-autonomous CPS/IoT device (client) can authorize/delegate their power to their trusted device. This allows the
        device to request the required resources and act/work on behalf of the principal. This can be achieved with the extension of OAuth grant
        types with the decentralized PoA-based authorization.</t>

      <t>The feature of multi-level authorization allows the agent to transfer the PoA to another agent. The parameter transferable in the PoA indicates the allowed number of transfers of
        the PoA. The first agent sends a different PoA with the root PoA inside to the second agent, by signing the secondary PoA with its private key. The signing along with
        the generation of secondary PoAs continues with the number of agents in the trust chain. The secondary PoAs can be traced back to the root PoA, which allows the resource owner to
        identify different agents in the trust chain.</t>
      <t>The operational assumptions for using this authorization grant type are:</t>

      <ul>
        <li>There is established mutual trust between the principal and the client (i.e., PoAs are only assigned
          to trusted parties).</li>
        <li>The client is an autonomous or semi-autonomous device with sufficient resources to perform authorization.</li>
        <li>The identity of the principal and client must be possible to verify. Whether this is based on a strong identity or only on public-private
          key challenges depend on the application.</li>

        <!--<li>previous approaches to PoA-based authorization, only the identity of the principal or
          client must be possible to verify, rather than the contents of the PoA. Other approaches use lightweight messages,
          but the proposed model's clients are not typically resource-constrained devices.</li> -->
      </ul>
      <t>While other approaches use lightweight messages, the PoA is an immutable signed message and assumes that the clients are
        typically not resource-constrained. A detailed explanation of PoA-based authorization and its differences between OAuth and other
        similar authorization standards can be found here (add information draft link here).</t>

      <section>
        <name>Requirements Language</name>
        <t>The key words "MUST", "MUST NOT", "REQUIRED", "SHALL",
          "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT
          RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
          interpreted as described in BCP 14 <xref target="RFC2119"/>
          <xref target="RFC8174"/> when, and only when, they appear in
          all capitals, as shown here.</t>
      </section>
      <!-- [CHECK] The 'Requirements Language' section is optional -->
      <section>
        <name>Roles</name>
        <t>There are five roles in the proposed grant type. The role principal is an addition to the existing roles of OAuth protocol.</t>

        <dl newline="true">
        <!-- Omit newline="true" if you want each definition to start on the same line as the corresponding term -->
          <dt>resource owner</dt>
            <dd>An entity capable of granting access to a protected resource.
              When a resource owner is a person, it is referred to as an
              end-user.</dd>
          <dt>resource server</dt>
            <dd>The server hosting the protected resources, is capable of accepting
              and responding to protected resource requests using access tokens.
            </dd>
          <dt>client or Agent</dt>
          <dd>The term "client" does
            not imply any particular implementation characteristics (e.g.,
            whether the application executes on a server, a desktop, or other
            devices). It receives the PoA from the principal and requests the
            protected resources from the resource owner via the authorization server on behalf of the principal.
          </dd>

          <dt>authorization server</dt>
          <dd>The server issues access tokens to the client/agent after successfully
            authenticating the resource owner and obtaining authorization.
          </dd>
          <dt>principal</dt>
          <dd>An entity that generates, signs, and sends the PoA
            to the client/agent. It may or may not be the same as the resource owner. In many PoA cases, it is considered to be a different
            entity.</dd>


        </dl>

        <!--
        <dt>client/agent</dt>
        <dd>Application that receives the PoA from the principal and request the
          protected resources from the resource owner via authorization server on behalf of the principal.
          It can be a web application or a CPS/IoT device with sufficient resources.</dd>
        <dt>authorization server</dt>
        <dd>The server verifies the client and issues access tokens to the client upon successful verification and authentication with
          the resource owner.</dd>
        <dt>resource owner</dt>
        <dd>The third party with a server that stores
          the information and credentials entitled to the principal. It serves clients according to
          subgrants defined in PoAs.</dd>
        <dt>resource server</dt>
        <dd>The server that hosts the protected resources owned by the resource owner.</dd> -->

      </section>
<!--
      <section>
        <name>Usecase: PoA based OAuth grant type</name>
          <t>The proposed OAuth grant type based on PoA-based authorization can be
            used in different usecases. One common example is the pharmacy usecase.
            Consider that the principal has a prescription to get at the pharmacy and
            he/she is currently not available. The principal can generate and send a Power of Attorney
            to their trusted client. This enables the client to obtain the prescribed medication on the
            principal's behalf. Using the PoA, the pharmacy (resource owner) authorizes the client.</t>
      </section> -->

    </section>

    <section>
      <name>Obtaining Authorization</name>
      <t>OAuth defines four grant types: authorization code, implicit,
        resource owner password credentials, and client credentials.  It also
        provides an extension mechanism for defining additional grant types. The proposed newer grant type is PoA-based authorization.
      </t>
      <section>
        <name>PoA based authorization</name>
        <t> PoA-based authorization is used in a scenario, where the principal (user) requires its trusted client/agent to access resources
          owned by the resource owner (may be different from the principal, based on already established trust relation between the principal and the resource owner) on behalf of the principal, even if the principal
          is not online. PoA-based authorization adds the principal role to the OAuth protocol
          <xref target="OAuth"/>. Figure 1 shows the PoA-based OAuth grant type.</t>


        <figure>
          <name>Protocol flow of PoA based OAuth grant type</name>
          <sourcecode name="/figure1.png" markers="false">
            <![CDATA[

            +---------+
            |         |
            |Principal|
            |         |
            +---------+
              |     ^
              |     |
             (A)   (H)
              |     |
              v     |
            +---------+                           +--------------+
            |         |                           |              |
            |         |                           |              |
            |         |--(B)--PoA,Authentication->|   Resource   |
            |         |                           |    Owner     |
            |         |<-(C)-Agent/client code----|              |
            |         |                           |              |
            | Client  |                           +--------------+
            |  or     |                           +--------------+
            | Agent   |                           |              |
            |         |--(D)-Agent/client code--->|              |
            |         |                           |Authorization |
            |         |<-(E)----Access token------|    Server    |
            |         |                           |              |
            +---------+                           +--------------+
              |     ^
              |     |
             (F)   (G)
              |     |
              v     |
            +---------+
            |         |
            | Resource|
            |  Server |
            |         |
            +---------+

            ]]>

          </sourcecode>
          <!-- [CHECK] markers="true" means that the rendered file will have <CODE BEGINS> and <CODE ENDS> added -->
        </figure>
        <t>The flow illustrated in Figure 1 includes the following steps:</t>

        <dl newline="false" spacing="normal" indent="6">
          <dt>(A)</dt>
          <dd>PoA is generated by the Principal and is sent to his/her trusted client. This allows the client
            to act/work on behalf of the principal. The structure of the PoA is detailed in section <xref target="PoAstructure"/></dd>
          <dt>(B)</dt>
          <dd>Client requests the authorization code from the resource owner
            by providing the PoA from the principal.</dd>
          <dt>(C)</dt>
          <dd>Resource owner issues the authorization code upon verification to the client. This assumes that mutual trust has
            been established between the resource owner and the principal.</dd>
          <dt>(D)</dt>
          <dd>The client requests an access token from the authorization
            server's token endpoint by including the authorization code
            received in the previous step.</dd>
          <dt>(E)</dt>
          <dd>The authorization server authenticates the client and validates the
            authorization code. If valid, the authorization server responds with
            an access token and, optionally, a refresh token.</dd>
          <dt>(F)</dt>
          <dd>Client sends the access token to the resource server to obtain the protected resources on behalf of the principal.</dd>
          <dt>(G)</dt>
          <dd>Resource server verifies the access token and provides the protected resources to the client.</dd>
          <dt>(H)</dt>
          <dd>Client may or may not send a report (e.g., log details) on the work back to the principal.</dd>
        </dl>

        <section>
          <name>PoA generation for the client/agent</name>
          <section anchor="PoAstructure">
          <t>The PoAs are self-contained tokens that are
            structured in JWT format. The PoA can be in both JSON or CBOR form and is
            digitally signed by the principal using his/her private key. PoA can be sent in clear text format or compressed binary format (to be defined).
            The various parameters included in a PoA are the following:</t>
          <dl newline="true">
            <!-- Omit newline="true" if you want each definition to start on the same line as the corresponding term -->
            <dt>Principal Public Key</dt>
            <dd>REQUIRED. The public key, which uniquely identifies the
              principal who generates the PoA. We assume that the public
              key is generated using a secure public-key algorithm by the
              principal. With this parameter, the authorization server can
              identify the person who generated the PoA.</dd>
            <dt>Principal Name</dt>
            <dd>OPTIONAL. The human-readable name of the principal,
              which is additional information about the principal.</dd>
            <dt>Resource Owner ID</dt>
            <dd>REQUIRED. The unique identifier or the public key of
              the resource owner from where the protected resources are
              granted.</dd>
            <dt>Agent Public Key</dt>
            <dd>REQUIRED. The public key, which uniquely identifies
              the agent who receives the PoA from the principal. We
              assume that the agent public key is generated using a secure
              public-key algorithm by the owner. This parameter helps the
              trusted server to identify the agent and check whether it is
              genuine or not.</dd>
            <dt>Agent Name</dt>
            <dd>OPTIONAL. The human-readable name of the agent,
              which is additional information about the agent.</dd>
            <dt>Signing Algorithm</dt>
            <dd>OPTIONAL. The name of the signature algorithm used by
              the principal to digitally sign the PoA.</dd>
            <dt>Transferable</dt>
            <dd>REQUIRED. It is a positive integer defining how many
              steps the PoA can be transferred. Default is 0, which means
              that it is not transferable. A PoA can be transferred by
              including it in another PoA, i.e., it is signed in several
              delegation steps (where the number is decreased by one in
              each step).</dd>
            <dt>iat (Issued at)</dt>
            <dd>REQUIRED. The time at which the PoA is issued by the
              principal to the agent.</dd>
            <dt>eat (Expires at)</dt>
            <dd>REQUIRED. The time at which the PoA expires. This
              parameter is predefined by the principal in the PoA and the
              PoA will be invalid after eat.</dd>
            <dt>Metadata</dt>
            <dd>OPTIONAL. The metadata is associated with the specific
              application use-case. This parameter includes different sub-
              parameters that add application-specific information to the
              PoA.</dd>
          </dl>
        </section>
        <section>
          <name>PoA interpretation</name>
          <t>PoA is interpreted whenever the recipient receives the PoA. This can be done using a third-party centralized server,
            where the interpretation can be performed, which is a similar approach to a public key certificate authority. Another approach is to enable PoA interpretation
            at every entity point in the PoA-based authorization. This can be achieved by downloading a common library <xref target="PoAlibrary"/> to encode and decode the
            PoA. This is a similar approach to for example PGP.</t>
        </section>
        <section>
          <name>Authorization Request</name>
          <t>This specification adds a new OAuth endpoint: the client authorization endpoint. This is different from the OAuth authorization endpoint defined
            in <xref target="OAuth"/>. Here, the client constructs the request URI by including the "poa" parameter along with the other parameters as defined in OAuth specification
            to the query component of the authorization endpoint URI
            using the "application/x-www-form-urlencoded". </t>
          <dl>
            <dt>response_type</dt>
              <dd>REQUIRED.  Value MUST be set to "code".</dd>
            <dt>client_id</dt>
              <dd>REQUIRED.  The client identifier.</dd>
            <dt>poa</dt>
              <dd>REQUIRED.  The poa as described in the previous section <xref target="PoAstructure"/></dd>
            <dt>redirect_uri</dt>
              <dd>OPTIONAL. As described in OAuth spec. </dd>
            <dt>scope</dt>
              <dd>OPTIONAL.  The scope of the access request.</dd>
            <dt>state</dt>
              <dd>RECOMMENDED.  An opaque value used by the client to maintain
                state between the request and callback.</dd>
          </dl>
          <t>The authorization server validates the request including the "poa", to ensure that all
            required parameters are present and valid. If the request is valid,
            the authorization server authenticates the resource owner and obtains
            an authorization decision (e.g., by asking the resource owner or by
            establishing approval via other means).</t>

        </section>
        <section>
          <name>Authorization Response</name>
          <t>If the resource owner grants the access request, the authorization
            server issues an authorization code and delivers it to the client same as the OAuth specification.</t>
          <section>
            <name>Error Response</name>
            <t>If the request fails due to a missing parameter in the PoA, invalid time, or any suspicious parameters in the PoA, the client
              can reject the PoA and send an error response back to the principal. In the case of multi-level authorization, the agent in the
              trust chain can send the error response back to the principal as well as to the agent before.
              If the resource owner fails to verify the PoA, the resource owner can inform and ask the agent or principal for more data for verification.</t>
          </section>
        </section>
        <section>
          <name>Access Token Request and response</name>
          <t>Access token request and response between the roles authorization server and the client is done according to the Oauth
          specification.</t>
        </section>
        <section>
          <name>Send a report back to principal</name>
          <t>This is an optional step, where the client can send a report (e.g., log details) to the principal on the work done.</t>
        </section>

      </section>
      </section>
      <section>
        <name>Security considerations</name>
        <section>
          <name>Spoofing</name>
          <t>Spoofing is not a threat in the proposed model. This is because the PoA is digitally signed using a standard public key
            approach and there are public keys inside the PoA to identify the principals and agents. Hence, even when the attacker sends
            a poa signed with his/her private key, the agent checks the public key and rejects the poa because
            it is not part of the agent's trusted public keys. </t>
        </section>
        <section>
          <name>Sniffing/eavesdropping the PoA and MITM</name>
          <t>The PoA that is sent from principal to agent can be eavesdropped on. Even though the data inside the PoA may not be sensitive, it's recommended to use TLS
            for better security and to eliminate privacy attacks. This is the same for the Man-In-The-Middle (MITM) attack. </t>
        </section>

        <section>
          <name>Denial of Service</name>
          <t>An external agent interrupts the data flowing across the trust boundary in either direction. DoS is mitigated or can decrease the impact by making the attacker
            consume more of his resources than yours to launch the attack. Make the attacker reply using information from previous message exchanges, to prove
            they can receive data from you <xref target="rfc3552"/>. Individual targeted DoS attacks is difficult to prevent in this design.</t>
        </section>

        <section>
          <name>Cross Site Scripting (XSS) or Code Injection</name>
          <t>While downloading the public library to generate or validate the PoA, the entity might download a malicious one instead of the legitimate lib. This could be prevented
          with input sanitization or filtering techniques.</t>
        </section>
      </section>
    </section>


    <!-- NOTE: The Acknowledgements and Contributors sections are at the end of this template -->
  </middle>

  <back>
    <references>
      <name>References</name>
      <references>
        <name>Normative References</name>
        
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.8174.xml"/>
        <xi:include href="https://www.rfc-editor.org/refs/bibxml/reference.RFC.2119.xml"/>


        <!-- The recommended and simplest way to include a well known reference -->
        
      </references>
 
      <references>
        <name>Informative References</name>

        <reference anchor="OAuth">
          <front>
            <title>The OAuth 2.0 authorization framework</title>
            <author initials="Hardt, Dick">
              <organization>Internet Engineering Task Force</organization>
            </author>
            <date year="2012"/>
          </front>
        </reference>

        <reference anchor="PoAlibrary">
          <front>
            <title>https://test.pypi.org/project/poalib-srevat/0.0.1/</title>
            <author initials="Sreelakshmi">
              <organization>TestPyPI</organization>
            </author>
            <date year="2022"/>
          </front>
        </reference>

        <reference anchor="rfc3552">
          <front>
            <title>Guidelines for Writing RFC Text on Security Considerations</title>
            <author initials="Rescorla, Korver">
              <organization>Internet Engineering Task Force</organization>
            </author>
            <date year="2003"/>
          </front>
        </reference>

      </references>
    </references>
    
    <!--<section>
      <name>Appendix 1 [REPLACE/DELETE]</name>
      <t>This becomes an Appendix [REPLACE]</t>
    </section>

    <section anchor="Acknowledgements" numbered="false"> -->
      <!-- [REPLACE/DELETE] an Acknowledgements section is optional -->
      <!--<name>Acknowledgements</name>
      <t>This template uses extracts from templates written by Pekka Savola, Elwyn Davies and 
        Henrik Levkowetz. [REPLACE]</t>
    </section> -->
    
    <section anchor="Contributors" numbered="false">
      <!-- [REPLACE/DELETE] a Contributors section is optional -->
      <name>Contributors</name>
      <t>Thanks to all of the contributors.</t>
      <!-- [CHECK] it is optional to add a <contact> record for some or all contributors -->
    </section>
    
 </back>
</rfc>
