Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for device-code authorization #168

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog
## [1.1.0] - 2018-05-20
## [1.2.0] - 2021-02-12
### Added
- Added support for device-code authorization

## [1.1.0] - 2020-05-20
### Changed
- Removed Python 2.7 support

### Fixed
- Add back missing classifiers in `setup.py`

Expand Down Expand Up @@ -124,6 +131,7 @@ additional issues are invited for full support.
### Added
- First release using the Python [requests](http://docs.python-requests.org/en/latest/) module

[1.2.0]: https://github.com/vimeo/vimeo.py/compare/1.1.0...1.2.0
[1.1.0]: https://github.com/vimeo/vimeo.py/compare/1.0.11...1.1.0
[1.0.11]: https://github.com/vimeo/vimeo.py/compare/1.0.10...1.0.11
[1.0.10]: https://github.com/vimeo/vimeo.py/compare/1.0.9...1.0.10
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import setup

setup(name='PyVimeo',
version='1.1.0',
version='1.2.0',
description='Simple interaction with the Vimeo API.',
url='https://developer.vimeo.com/',
author='Vimeo',
Expand Down
37 changes: 37 additions & 0 deletions vimeo/auth/device_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#! /usr/bin/env python
# encoding: utf-8

from .base import AuthenticationMixinBase
from . import GrantFailed


class DeviceCodeMixin(AuthenticationMixinBase):
"""Implement helpers for the Device Code grant for OAuth2."""

def load_device_code(self, scope):
"""Perform the request for device code."""
code, headers, resp = self.call_grant(
"/oauth/device", {
"grant_type": "device_grant",
"scope": scope
})

if not code == 200:
raise GrantFailed()

return resp

def device_code_authorize(self, user_code, device_code):
"""Perform the authorization step after the user entered the device code."""
code, headers, resp = self.call_grant(
"/oauth/device/authorize", {
"user_code": user_code,
"device_code": device_code
})

if not code == 200:
raise GrantFailed()

self.token = resp["access_token"]

return self.token, resp["user"], resp["scope"]
5 changes: 3 additions & 2 deletions vimeo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@
import requests
from .auth.client_credentials import ClientCredentialsMixin
from .auth.authorization_code import AuthorizationCodeMixin
from .auth.device_code import DeviceCodeMixin
from .upload import UploadMixin
from .exceptions import APIRateLimitExceededFailure


class VimeoClient(ClientCredentialsMixin, AuthorizationCodeMixin, UploadMixin):
class VimeoClient(ClientCredentialsMixin, AuthorizationCodeMixin, DeviceCodeMixin, UploadMixin):
"""Client handle for the Vimeo API."""

API_ROOT = "https://api.vimeo.com"
HTTP_METHODS = {'head', 'get', 'post', 'put', 'patch', 'options', 'delete'}
ACCEPT_HEADER = "application/vnd.vimeo.*;version=3.4"
USER_AGENT = "pyvimeo 1.0.11; (http://developer.vimeo.com/api/docs)"
USER_AGENT = "pyvimeo 1.2.0; (http://developer.vimeo.com/api/docs)"

def __init__(self, token=None, key=None, secret=None, *args, **kwargs):
"""Prep the handle with the authentication information."""
Expand Down