• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

requests / requests-oauthlib / 8621812797

09 Apr 2024 08:22PM UTC coverage: 90.097%. Remained the same
8621812797

Pull #538

github

web-flow
Merge 59f3d6a0e into 45eca1a69
Pull Request #538: Added secrets to actions to run test example

464 of 515 relevant lines covered (90.1%)

5.41 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.86
/requests_oauthlib/oauth2_auth.py
1
from oauthlib.oauth2 import WebApplicationClient, InsecureTransportError
6✔
2
from oauthlib.oauth2 import is_secure_transport
6✔
3
from requests.auth import AuthBase
6✔
4

5

6
class OAuth2(AuthBase):
6✔
7
    """Adds proof of authorization (OAuth2 token) to the request."""
8

9
    def __init__(self, client_id=None, client=None, token=None):
6✔
10
        """Construct a new OAuth 2 authorization object.
11

12
        :param client_id: Client id obtained during registration
13
        :param client: :class:`oauthlib.oauth2.Client` to be used. Default is
14
                       WebApplicationClient which is useful for any
15
                       hosted application but not mobile or desktop.
16
        :param token: Token dictionary, must include access_token
17
                      and token_type.
18
        """
19
        self._client = client or WebApplicationClient(client_id, token=token)
6✔
20
        if token:
6✔
21
            for k, v in token.items():
6✔
22
                setattr(self._client, k, v)
6✔
23

24
    def __call__(self, r):
6✔
25
        """Append an OAuth 2 token to the request.
26

27
        Note that currently HTTPS is required for all requests. There may be
28
        a token type that allows for plain HTTP in the future and then this
29
        should be updated to allow plain HTTP on a white list basis.
30
        """
31
        if not is_secure_transport(r.url):
6✔
32
            raise InsecureTransportError()
×
33
        r.url, r.headers, r.body = self._client.add_token(
6✔
34
            r.url, http_method=r.method, body=r.body, headers=r.headers
35
        )
36
        return r
6✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc