# -*- coding: utf-8 -*-
"""This module contains the Authorization object."""
from __future__ import unicode_literals
from .decorators import requires_basic_auth
from .models import GitHubCore
class Authorization(GitHubCore):
"""Representation of an OAuth Authorization.
See also: https://developer.github.com/v3/oauth_authorizations/
This object has the following attributes:
.. attribute:: app
Details about the application the authorization was created for.
.. attribute:: created_at
A :class:`~datetime.datetime` representing when this authorization was
created.
.. attribute:: fingerprint
.. versionadded:: 1.0
The optional parameter that is used to allow an OAuth application to
create multiple authorizations for the same user. This will help
distinguish two authorizations for the same app.
.. attribute:: hashed_token
.. versionadded:: 1.0
This is the base64 of the SHA-256 digest of the token.
.. seealso::
`Removing Authorization Tokens`_
The blog post announcing the removal of :attr:`token`.
.. attribute:: id
The unique identifier for this authorization.
.. attribute:: note_url
The URL that points to a longer description about the purpose of this
autohrization.
.. attribute:: note
The short note provided when this authorization was created.
.. attribute:: scopes
The list of scopes assigned to this token.
.. seealso::
`Scopes for OAuth Applications`_
GitHub's documentation around available scopes and what they
mean
.. attribute:: token
If this authorization was created, this will contain the full token.
Otherwise, this attribute will be an empty string.
.. attribute:: token_last_eight
.. versionadded:: 1.0
The last eight characters of the token. This allows users to identify
a token after the initial retrieval.
.. attribute:: updated_at
A :class:`~datetime.datetime` representing when this authorization was
most recently updated.
.. _Scopes for OAuth Applications:
https://developer.github.com/apps/building-oauth-apps/scopes-for-oauth-apps/
.. _Removing Authorization Tokens:
https://developer.github.com/changes/2014-12-08-removing-authorizations-token/#what-should-you-do
"""
def _update_attributes(self, auth):
self._api = auth["url"]
self.app = auth["app"]
self.created_at = self._strptime(auth["created_at"])
self.fingerprint = auth["fingerprint"]
self.id = auth["id"]
self.note_url = auth["note_url"]
self.note = auth["note"]
self.scopes = auth["scopes"]
self.token = auth["token"]
self.token_last_eight = auth["token_last_eight"]
self.updated_at = self._strptime(auth["updated_at"])
def _repr(self):
return "