#-*- coding: utf-8 -*-

from .grant import Grant
from ..endpoint import AuthorizationEndpoint


class ImplicitGrant(Grant):
    """
    The implicit grant type is used to obtain access tokens (it does not
    support the issuance of refresh tokens) and is optimized for public
    clients known to operate a particular redirection URI.  These clients
    are typically implemented in a browser using a scripting language
    such as JavaScript.

     +----------+
     | Resource |
     |  Owner   |
     |          |
     +----------+
          ^
          |
         (B)
     +----|-----+          Client Identifier     +---------------+
     |         -+----(A)-- & Redirection URI --->|               |
     |  User-   |                                | Authorization |
     |  Agent  -|----(B)-- User authenticates -->|     Server    |
     |          |                                |               |
     |          |<---(C)--- Redirection URI ----<|               |
     |          |          with Access Token     +---------------+
     |          |            in Fragment
     |          |                                +---------------+
     |          |----(D)--- Redirection URI ---->|   Web-Hosted  |
     |          |          without Fragment      |     Client    |
     |          |                                |    Resource   |
     |     (F)  |<---(E)------- Script ---------<|               |
     |          |                                +---------------+
     +-|--------+
       |    |
      (A)  (G) Access Token
       |    |
       ^    v
     +---------+
     |         |
     |  Client |
     |         |
     +---------+

    Note: The lines illustrating steps (A) and (B) are broken into two
    parts as they pass through the user-agent.

                       Figure 4: Implicit Grant Flow
    """
    
    def get_redirection_uri(self, expires_in):

        self._authorization_endpoint = AuthorizationEndpoint(self._server, self._request, self._client)
        return self._authorization_endpoint.implicit(expires_in)
