Skip to content

Commit

Permalink
Merge pull request #45 from Colin-b/develop
Browse files Browse the repository at this point in the history
Release 5.0.0
  • Loading branch information
Colin-b authored Nov 21, 2019
2 parents ce7acf7 + 40f4b19 commit e4daf09
Show file tree
Hide file tree
Showing 34 changed files with 2,886 additions and 1,386 deletions.
22 changes: 21 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [5.0.0] - 2019-11-21
### Changed
- OAuth2ClientCredentials username parameter is now client_id
- OAuth2ClientCredentials password parameter is now client_secret
- requests_auth.InvalidGrantRequest is now raised instead of requests.HTTPError in case a grant request was invalid.
- requests_auth.InvalidGrantRequest is now raised instead of requests_auth.GrantNotProvided in case a browser grant request was invalid.
- There is no info logging anymore. If you want to have those information (browser opening on a specific URL, requests received by the OAUth2 server), you will have to put requests_auth logger to DEBUG.

### Removed
- Support for Python < 3.6
- requests_auth.OAuth2Flow enum, use the proper auth class instead.
- requests_auth.okta function, use the proper auth class instead.
- requests_auth.aad function, use the proper auth class instead.
- requests_auth.oauth2 function, use the proper auth class instead.
- str representation of auth classes.

### Fixed
- timeout parameter can now be a floating point value. (was only integer previously)

## [4.1.0] - 2019-11-13
### Added
- module version is now publicly available.
Expand Down Expand Up @@ -87,7 +106,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Public release

[Unreleased]: https://github.com/Colin-b/requests_auth/compare/v4.1.0...HEAD
[Unreleased]: https://github.com/Colin-b/requests_auth/compare/v5.0.0...HEAD
[5.0.0]: https://github.com/Colin-b/requests_auth/compare/v4.1.0...v5.0.0
[4.1.0]: https://github.com/Colin-b/requests_auth/compare/v4.0.1...v4.1.0
[4.0.1]: https://github.com/Colin-b/requests_auth/compare/v4.0.0...v4.0.1
[4.0.0]: https://github.com/Colin-b/requests_auth/compare/v3.0.0...v4.0.0
Expand Down
19 changes: 11 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ Before creating an issue please make sure that it was not already reported.

#### Code

1) Create a new branch based on *develop* branch.
2) Add your changes.
3) Follow [Black](https://black.readthedocs.io/en/stable/) code formatting.
* Install pre-commit python module using pip: **python -m pip install pre-commit**
* To add the pre-commit hook, after the installation run: **pre-commit install**
4) Add at least one test case.
1) Create a new branch based on `develop` branch.
2) Fetch all dev dependencies.
* Install required python modules using `pip`: **python -m pip install .[testing]**
3) Ensure tests are ok by running them using [`pytest`](http://doc.pytest.org/en/latest/index.html).
4) Add your changes.
5) Follow [Black](https://black.readthedocs.io/en/stable/) code formatting.
* Install [pre-commit](https://pre-commit.com) python module using `pip`: **python -m pip install pre-commit**
* To add the [pre-commit](https://pre-commit.com) hook, after the installation run: **pre-commit install**
6) Add at least one [`pytest`](http://doc.pytest.org/en/latest/index.html) test case.
* Unless it is an internal refactoring request or a documentation update.
5) Increment [version number](https://semver.org) and add related [changelog entry](https://keepachangelog.com/en/1.0.0/).
7) Increment [version number](https://semver.org) and add related [changelog entry](https://keepachangelog.com/en/1.0.0/).
* Unless it is a documentation update.

##### Changelog entry
Expand All @@ -55,7 +58,7 @@ Once the changelog entry is added, please don't forget to also add the link to t
#### Enter pull request

1) Go to the *Pull requests* tab and click on the *New pull request* button.
2) *base* should always be set to development and it should be compared to your branch.
2) *base* should always be set to `develop` and it should be compared to your branch.
3) Title should be a small sentence describing the request.
3) The comment should contains as much information as possible
* Actual behavior (before the new code)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2018 Colin Bounouar
Copyright (c) 2020 Colin Bounouar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
<p align="center">
<a href="https://pypi.org/project/requests-auth/"><img alt="pypi version" src="https://img.shields.io/pypi/v/requests_auth"></a>
<img alt="Build status" src="https://img.shields.io/badge/build-passing-brightgreen">
<img alt="Coverage" src="https://img.shields.io/badge/coverage-94%25-brightgreen">
<img alt="Coverage" src="https://img.shields.io/badge/coverage-100%25-brightgreen">
<a href="https://github.com/psf/black"><img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg"></a>
<img alt="Number of tests" src="https://img.shields.io/badge/tests-95 passed-blue">
<img alt="Number of tests" src="https://img.shields.io/badge/tests-167 passed-blue">
<a href="https://pypi.org/project/requests-auth/"><img alt="Number of downloads" src="https://img.shields.io/pypi/dm/requests_auth"></a>
</p>

Provides authentication classes to be used with [`requests`][1] [authentication parameter][2].
Expand Down Expand Up @@ -264,16 +265,16 @@ Use `requests_auth.OAuth2ClientCredentials` to configure this kind of authentica
import requests
from requests_auth import OAuth2ClientCredentials

requests.get('http://www.example.com', auth=OAuth2ClientCredentials('https://www.token.url', 'user name', 'user password'))
requests.get('http://www.example.com', auth=OAuth2ClientCredentials('https://www.token.url', client_id='id', client_secret='secret'))
```

#### Parameters

| Name | Description | Mandatory | Default value |
|:-------------------|:---------------------------------------------|:----------|:--------------|
| `token_url` | OAuth 2 token URL. | Mandatory | |
| `username` | Resource owner user name. | Mandatory | |
| `password` | Resource owner password. | Mandatory | |
| `client_id` | Resource owner user name. | Mandatory | |
| `client_secret` | Resource owner password. | Mandatory | |
| `timeout` | Maximum amount of seconds to wait for a token to be received once requested. | Optional | 60 |
| `header_name` | Name of the header field used to send token. | Optional | Authorization |
| `header_value` | Format used to send the token value. "{token}" must be present as it will be replaced by the actual token. | Optional | Bearer {token} |
Expand Down Expand Up @@ -378,6 +379,8 @@ aad = AzureActiveDirectoryImplicit(tenant_id='45239d18-c68c-4c47-8bdd-ce71ea1d50
requests.get('http://www.example.com', auth=aad)
```

You can retrieve Microsoft Azure Active Directory application information thanks to the [application list on Azure portal](https://portal.azure.com/#blade/Microsoft_AAD_IAM/StartboardApplicationsMenuBlade/AllApps/menuId/).

###### Parameters

| Name | Description | Mandatory | Default value |
Expand Down Expand Up @@ -418,6 +421,8 @@ aad = AzureActiveDirectoryImplicitIdToken(tenant_id='45239d18-c68c-4c47-8bdd-ce7
requests.get('http://www.example.com', auth=aad)
```

You can retrieve Microsoft Azure Active Directory application information thanks to the [application list on Azure portal](https://portal.azure.com/#blade/Microsoft_AAD_IAM/StartboardApplicationsMenuBlade/AllApps/menuId/).

###### Parameters

| Name | Description | Mandatory | Default value |
Expand Down
79 changes: 1 addition & 78 deletions requests_auth/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
from enum import Enum, auto
import warnings

from requests_auth.authentication import (
Basic,
HeaderApiKey,
Expand Down Expand Up @@ -29,80 +26,6 @@
StateNotProvided,
InvalidToken,
TokenExpiryNotProvided,
InvalidGrantRequest,
)
from requests_auth.version import __version__


class OAuth2Flow(Enum):
Implicit = (auto(),)
PasswordCredentials = (auto(),) # Also called Resource Owner Password Credentials
ClientCredentials = (auto(),) # Also called Application
AuthorizationCode = (auto(),) # Also called AccessCode
PKCE = (auto(),)


def oauth2(flow, *args, **kwargs):
"""
Create a new generic OAuth2 authentication class.
:param flow: OAuth2 flow
:param args: all mandatory parameters that should be provided for this flow.
:param kwargs: optional parameters that can be provided for this flow.
:return: The newly created OAuth2 authentication class.
"""
warnings.warn(
"oauth2 function will be removed in the future. Use Oauth2* class instead.",
DeprecationWarning,
)
if OAuth2Flow.Implicit == flow:
return OAuth2Implicit(*args, **kwargs)
if OAuth2Flow.AuthorizationCode == flow:
return OAuth2AuthorizationCode(*args, **kwargs)
if OAuth2Flow.PKCE == flow:
return OAuth2AuthorizationCodePKCE(*args, **kwargs)
if OAuth2Flow.ClientCredentials == flow:
return OAuth2ClientCredentials(*args, **kwargs)
if OAuth2Flow.PasswordCredentials == flow:
return OAuth2ResourceOwnerPasswordCredentials(*args, **kwargs)


def okta(flow, *args, **kwargs):
"""
Create a new OKTA authentication class.
:param flow: OAuth2 flow
:param args: all mandatory parameters that should be provided for this flow.
:param kwargs: optional parameters that can be provided for this flow.
:return: The newly created OKTA authentication class.
"""
warnings.warn(
"okta function will be removed in the future. Use Okta* class instead.",
DeprecationWarning,
)
if OAuth2Flow.Implicit == flow:
return OktaImplicit(*args, **kwargs)
if OAuth2Flow.AuthorizationCode == flow:
return OktaAuthorizationCode(*args, **kwargs)
if OAuth2Flow.ClientCredentials == flow:
return OktaClientCredentials(*args, **kwargs)
raise Exception("{0} flow is not handled yet in OKTA.".format(flow))


def aad(flow, *args, **kwargs):
"""
Create a new Azure Active Directory authentication class.
:param flow: OAuth2 flow
:param args: all mandatory parameters that should be provided for this flow.
:param kwargs: optional parameters that can be provided for this flow.
:return: The newly created Azure Active Directory authentication class.
"""
warnings.warn(
"aad function will be removed in the future. Use AzureActiveDirectory* class instead.",
DeprecationWarning,
)
if OAuth2Flow.Implicit == flow:
return AzureActiveDirectoryImplicit(*args, **kwargs)
raise Exception(
"{0} flow is not handled yet in Azure Active Directory.".format(flow)
)
Loading

0 comments on commit e4daf09

Please sign in to comment.