99from __future__ import unicode_literals
1010
1111from json import dumps
12+ from github3 .auths import Authorization
1213from uritemplate import URITemplate
1314from .events import Event
1415from .models import GitHubObject , GitHubCore , BaseAccount
@@ -29,6 +30,7 @@ class Key(GitHubCore):
2930 k1.id == k2.id
3031 k1.id != k2.id
3132 """
33+
3234 def _update_attributes (self , key , session = None ):
3335 self ._api = key .get ('url' , '' )
3436 #: The text of the actual key
@@ -78,6 +80,7 @@ class Plan(GitHubObject):
7880 <http://developer.github.com/v3/users/#get-the-authenticated-user>`_
7981 documentation for more specifics.
8082 """
83+
8184 def _update_attributes (self , plan ):
8285 #: Number of collaborators
8386 self .collaborators = plan .get ('collaborators' )
@@ -103,7 +106,6 @@ def is_free(self):
103106
104107
105108class User (BaseAccount ):
106-
107109 """The :class:`User <User>` object. This handles and structures information
108110 in the `User section <http://developer.github.com/v3/users/>`_.
109111
@@ -416,3 +418,23 @@ def rename(self, login):
416418 resp = self ._boolean (self ._patch (url , data = payload ), 202 , 403 )
417419 return resp
418420
421+ @requires_auth
422+ def authorize (self , scopes = None ):
423+ """Obtain an impersonation token for the user.
424+
425+ The retrieved token will allow impersonation of the user.
426+ This is only available for admins of a GitHub Enterprise instance.
427+
428+ :param list scopes: (optional), areas you want this token to apply to,
429+ i.e., 'gist', 'user'
430+ :returns: :class:`Authorization <Authorization>`
431+ """
432+ url = self ._build_url ('admin' , 'users' , self .id , 'authorizations' )
433+ data = {}
434+
435+ if scopes :
436+ data ['scopes' ] = scopes
437+
438+ json = self ._json (self ._post (url , data = data ), 201 )
439+
440+ return self ._instance_or_null (Authorization , json )
0 commit comments