httpie-asap-auth 0.4.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,149 @@
1
+ Metadata-Version: 2.4
2
+ Name: httpie-asap-auth
3
+ Version: 0.4.0
4
+ Summary: ASAP Auth plugin for HTTPie.
5
+ Author-email: Jason Friedland <jason@friedland.id.au>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2017 Jason Friedland
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Homepage, https://github.com/jasonfriedland/httpie-asap-auth
29
+ Project-URL: Download, https://github.com/jasonfriedland/httpie-asap-auth
30
+ Classifier: Development Status :: 5 - Production/Stable
31
+ Classifier: Programming Language :: Python
32
+ Classifier: Programming Language :: Python :: 3
33
+ Classifier: Programming Language :: Python :: 3.8
34
+ Classifier: Programming Language :: Python :: 3.9
35
+ Classifier: Programming Language :: Python :: 3.10
36
+ Classifier: Programming Language :: Python :: 3.11
37
+ Classifier: Programming Language :: Python :: 3.12
38
+ Classifier: Programming Language :: Python :: 3.13
39
+ Classifier: Programming Language :: Python :: 3.14
40
+ Classifier: Environment :: Plugins
41
+ Classifier: License :: OSI Approved :: MIT License
42
+ Classifier: Topic :: Internet :: WWW/HTTP
43
+ Classifier: Topic :: Utilities
44
+ Requires-Python: >=3.8
45
+ Description-Content-Type: text/markdown
46
+ License-File: LICENSE
47
+ Requires-Dist: atlassian-jwt-auth>=10.1.0
48
+ Requires-Dist: httpie>=3.1.0
49
+ Dynamic: license-file
50
+
51
+ httpie-asap-auth
52
+ ================
53
+
54
+ [![PyPi Package](https://img.shields.io/pypi/v/httpie-asap-auth.svg)](https://pypi.python.org/pypi/httpie-asap-auth)
55
+ [![PyPi Versions](https://img.shields.io/pypi/pyversions/httpie-asap-auth.svg)](https://pypi.python.org/pypi/httpie-asap-auth)
56
+ [![Actions Status](https://github.com/jasonfriedland/httpie-asap-auth/workflows/test/badge.svg)](https://github.com/jasonfriedland/httpie-asap-auth/actions)
57
+ [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/ambv/black)
58
+
59
+ [ASAP](https://s2sauth.bitbucket.io/) Auth plugin for [HTTPie](https://httpie.org/).
60
+
61
+ Installation
62
+ ------------
63
+
64
+ pip install httpie-asap-auth
65
+
66
+ Python 3.8 through Python 3.14 are supported.
67
+
68
+ You should now see `asap` and `asapenv` under `--auth-type` in the `$ http --help` output.
69
+
70
+ Usage
71
+ -----
72
+
73
+ http --auth-type=asap --auth=path/to/asap.config http://example.com/
74
+
75
+ OR, to read from environment variables:
76
+
77
+ http --auth-type=asapenv --auth=audience[:subject] http://example.com/
78
+
79
+ Separate multiple audiences with a comma.
80
+
81
+ Example ASAP Config
82
+ -------------------
83
+
84
+ Store your ASAP config in a file following this format:
85
+
86
+ ```json
87
+ {
88
+ "issuer": "webapp/admin",
89
+ "kid": "webapp/admin/dev.pem",
90
+ "audience": [
91
+ "webapp"
92
+ ],
93
+ "sub": "administration",
94
+ "privateKey": "-----BEGIN RSA PRIVATE KEY-----\n ... \n-----END RSA PRIVATE KEY-----"
95
+ }
96
+ ```
97
+
98
+ NB. the subject (`sub` field) is optional.
99
+
100
+ Example Environment Variables
101
+ -----------------------------
102
+
103
+ ASAP_PRIVATE_KEY=data:application/pkcs8;kid=webapp;base64,...
104
+ ASAP_ISSUER=webapp/admin
105
+
106
+ Generate a Data URI
107
+ -------------------
108
+
109
+ Generate a data URI, with the key in PKCS8 from an RSA private key PEM file:
110
+
111
+ #!/bin/sh
112
+
113
+ # Usage: $0 privatekey.pem
114
+
115
+ KID=$(echo "$1" | sed 's|/|%2F|g')
116
+ KEY=$(openssl pkcs8 -topk8 -inform PEM -outform DER -in "$1" -nocrypt | base64 | tr '\n' ' ' | sed 's| ||g')
117
+
118
+ echo "data:application/pkcs8;kid=$KID;base64,$KEY"
119
+
120
+ (thanks to Brian McKenna)
121
+
122
+ Development
123
+ -----------
124
+
125
+ [Install uv](https://docs.astral.sh/uv/getting-started/installation/), then create
126
+ the development environment from the committed lockfile:
127
+
128
+ make sync
129
+
130
+ Run the test suite and formatter with the locked dependencies:
131
+
132
+ make test
133
+ make fmt
134
+
135
+ The formatter runs on Python 3.14 while preserving Python 3.8-compatible
136
+ syntax.
137
+
138
+ Upgrade all dependencies and review the resulting lockfile with:
139
+
140
+ make upgrade
141
+
142
+ Build the source and wheel distributions with:
143
+
144
+ make build
145
+
146
+ Maintainers can publish the built distributions after configuring uv's PyPI
147
+ credentials:
148
+
149
+ make publish
@@ -0,0 +1,7 @@
1
+ httpie_asap_auth.py,sha256=FtQEHPXhF1D69NztuU7n2S2HzYNmG32CMnY1yydk1GE,5172
2
+ httpie_asap_auth-0.4.0.dist-info/licenses/LICENSE,sha256=INjQn-bycyKJ-XE5hKB0qz8lll-nZr0wQcvCtsa1J3w,1072
3
+ httpie_asap_auth-0.4.0.dist-info/METADATA,sha256=dnpUY-KX_Etupwt8Qqv-gIr1QJfGyAdRvO0P7TidW4Y,5028
4
+ httpie_asap_auth-0.4.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
5
+ httpie_asap_auth-0.4.0.dist-info/entry_points.txt,sha256=TP9D4dtttRPWYnKzoXcxLOgiEAO5efIrkY3oLG6OB0A,134
6
+ httpie_asap_auth-0.4.0.dist-info/top_level.txt,sha256=qCXfxxUQYiHwPUqgmiIoGzHOxwh6SC-sjZ7rG_HJ7PE,17
7
+ httpie_asap_auth-0.4.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,3 @@
1
+ [httpie.plugins.auth.v1]
2
+ httpie_asap_auth = httpie_asap_auth:AsapAuthPlugin
3
+ httpie_asap_auth_env = httpie_asap_auth:AsapAuthEnvPlugin
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017 Jason Friedland
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ httpie_asap_auth
httpie_asap_auth.py ADDED
@@ -0,0 +1,171 @@
1
+ """
2
+ ASAP Auth plugin for HTTPie.
3
+ """
4
+
5
+ from __future__ import print_function
6
+
7
+ import json
8
+ import sys
9
+ import os
10
+
11
+ import atlassian_jwt_auth
12
+ import atlassian_jwt_auth.key
13
+ import atlassian_jwt_auth.signer
14
+ import atlassian_jwt_auth.contrib.requests
15
+
16
+ from httpie.status import ExitStatus
17
+ from httpie.plugins import AuthPlugin
18
+
19
+ __author__ = "Jason Friedland"
20
+ __licence__ = "MIT"
21
+
22
+
23
+ def fatal_plugin_error(message):
24
+ print(message, file=sys.stderr)
25
+ sys.exit(ExitStatus.PLUGIN_ERROR)
26
+
27
+
28
+ class AsapAuthPlugin(AuthPlugin):
29
+ """
30
+ ASAP Auth plugin for HTTPie, reading from config file.
31
+ """
32
+
33
+ name = "ASAP Auth"
34
+ auth_type = "asap"
35
+ description = "See: https://s2sauth.bitbucket.io/spec/ for details."
36
+
37
+ # Require but don't parse auth
38
+ auth_require = True
39
+ auth_parse = False
40
+ prompt_password = False
41
+
42
+ def get_auth(self, username=None, password=None):
43
+ """
44
+ Get ASAP Auth.
45
+
46
+ The --auth, -a option is used as the file path to the ASAP config
47
+ (in JSON form). We access this via self.raw_auth rather
48
+ than username/password.
49
+
50
+ :param str username: Unused.
51
+ :param str password: Unused.
52
+ :return: atlassian_jwt_auth.contrib.requests.JWTAuth
53
+ """
54
+ signer, audience, subject = self.parse_config_file(self.raw_auth)
55
+ return atlassian_jwt_auth.contrib.requests.JWTAuth(
56
+ signer, audience, additional_claims={"sub": subject} if subject else {}
57
+ )
58
+
59
+ @staticmethod
60
+ def parse_config_file(asap_config_file):
61
+ """
62
+ Parse ``asap_config_file`` JSON and return the signer.
63
+
64
+ :param str asap_config_file: Path to the ASAP config file.
65
+
66
+ :return: atlassian_jwt_auth.signer.JWTAuthSigner
67
+ :raises ExitStatus.PLUGIN_ERROR: Invalid config.
68
+ """
69
+ config = None
70
+
71
+ try:
72
+ with open(asap_config_file) as f:
73
+ config = json.load(f)
74
+ except IOError:
75
+ fatal_plugin_error("file not readable: {}".format(asap_config_file))
76
+ except ValueError:
77
+ fatal_plugin_error("invalid JSON config: {}".format(asap_config_file))
78
+
79
+ if config and not isinstance(config, dict):
80
+ fatal_plugin_error(
81
+ "invalid JSON config (expected dict): {}".format(asap_config_file)
82
+ )
83
+
84
+ try:
85
+ return (
86
+ atlassian_jwt_auth.create_signer(
87
+ config["issuer"], config["kid"], config["privateKey"]
88
+ ),
89
+ config["audience"],
90
+ config.get("sub"),
91
+ )
92
+ except KeyError as e:
93
+ fatal_plugin_error("expected key in config file: {}".format(e))
94
+
95
+
96
+ class AsapAuthEnvPlugin(AuthPlugin):
97
+ """
98
+ ASAP Auth plugin for HTTPie, reading from environment.
99
+ """
100
+
101
+ name = "ASAP Auth from environment"
102
+ auth_type = "asapenv"
103
+ description = "See: https://s2sauth.bitbucket.io/spec/ for details."
104
+
105
+ # Require but don't parse auth
106
+ auth_require = True
107
+ auth_parse = False
108
+ prompt_password = False
109
+
110
+ def get_auth(self, username=None, password=None):
111
+ """
112
+ Get ASAP Auth.
113
+
114
+ We use the environment variables ASAP_PRIVATE_KEY (data_uri form) and
115
+ ASAP_ISSUER for ASAP configuration, augmented by --auth, -a (which provides
116
+ audience1,audience2,...:subject). Subjects are optional.
117
+
118
+ :param str username: Unused.
119
+ :param str password: Unused.
120
+
121
+ :return: atlassian_jwt_auth.contrib.requests.JWTAuth
122
+ """
123
+ signer = self.construct_signer_from_env(os.environ)
124
+ audience, subject = self.parse_auth(self.raw_auth)
125
+ return atlassian_jwt_auth.contrib.requests.JWTAuth(
126
+ signer, audience, additional_claims={"sub": subject} if subject else {}
127
+ )
128
+
129
+ @staticmethod
130
+ def construct_signer_from_env(env):
131
+ """
132
+ Returns a new JWT signer initialised using values from the environment.
133
+
134
+ :param dict env: A dict holding the shell environment.
135
+
136
+ :return: atlassian_jwt_auth.signer.JWTAuthSigner
137
+ :raises ExitStatus.PLUGIN_ERROR: Invalid environment.
138
+ """
139
+ try:
140
+ provider = atlassian_jwt_auth.key.DataUriPrivateKeyRetriever(
141
+ env["ASAP_PRIVATE_KEY"]
142
+ )
143
+ return atlassian_jwt_auth.signer.JWTAuthSigner(env["ASAP_ISSUER"], provider)
144
+ except KeyError as e:
145
+ fatal_plugin_error("missing {} in environment".format(e))
146
+
147
+ @staticmethod
148
+ def parse_auth(auth):
149
+ """
150
+ Parse the ``auth`` arg and return the audience and subject.
151
+
152
+ >>> AsapAuthEnvPlugin.parse_auth("foo,bar:baz")
153
+ (['foo', 'bar'], 'baz')
154
+
155
+ >>> AsapAuthEnvPlugin.parse_auth(":baz")
156
+ ([''], 'baz')
157
+
158
+ >>> AsapAuthEnvPlugin.parse_auth("foo")
159
+ (['foo'], None)
160
+
161
+ :param str auth: The ``auth`` arg passed on the CLI. Contains the audience and subject.
162
+ :return: tuple(List[str], str)
163
+ """
164
+ auth = auth.split(":", 1)
165
+
166
+ if len(auth) == 1:
167
+ audience, subject = auth[0], None
168
+ else:
169
+ audience, subject = auth
170
+
171
+ return audience.split(","), subject