mcs-auth 0.1.0__tar.gz
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.
- mcs_auth-0.1.0/LICENSE +201 -0
- mcs_auth-0.1.0/PKG-INFO +89 -0
- mcs_auth-0.1.0/README.md +64 -0
- mcs_auth-0.1.0/pyproject.toml +34 -0
- mcs_auth-0.1.0/setup.cfg +4 -0
- mcs_auth-0.1.0/src/mcs/auth/challenge.py +42 -0
- mcs_auth-0.1.0/src/mcs/auth/mixin.py +55 -0
- mcs_auth-0.1.0/src/mcs/auth/ports.py +57 -0
- mcs_auth-0.1.0/src/mcs/auth/provider.py +42 -0
- mcs_auth-0.1.0/src/mcs/auth/static.py +40 -0
- mcs_auth-0.1.0/src/mcs_auth.egg-info/PKG-INFO +89 -0
- mcs_auth-0.1.0/src/mcs_auth.egg-info/SOURCES.txt +14 -0
- mcs_auth-0.1.0/src/mcs_auth.egg-info/dependency_links.txt +1 -0
- mcs_auth-0.1.0/src/mcs_auth.egg-info/top_level.txt +1 -0
- mcs_auth-0.1.0/tests/test_auth_mixin.py +95 -0
- mcs_auth-0.1.0/tests/test_static_provider.py +47 -0
mcs_auth-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
mcs_auth-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcs-auth
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Credential provider abstraction for the Model Context Standard.
|
|
5
|
+
Author-email: Danny Gerst <danny@dannygerst.de>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://www.modelcontextstandard.io
|
|
8
|
+
Project-URL: Source, https://github.com/modelcontextstandard/python-sdk
|
|
9
|
+
Keywords: mcs,modelcontextstandard,auth,credentials,oauth2,token
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Security
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# mcs-auth
|
|
27
|
+
|
|
28
|
+
The authentication backbone for the **Model Context Standard (MCS)**.
|
|
29
|
+
|
|
30
|
+
Stop wiring OAuth flows, API keys, and token refresh logic into every agent
|
|
31
|
+
you build. `mcs-auth` defines a universal `CredentialProvider` protocol --
|
|
32
|
+
one interface, any credential source. Your agent code never changes, no
|
|
33
|
+
matter how authentication works behind the scenes.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install mcs-auth
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## What's inside
|
|
42
|
+
|
|
43
|
+
| Component | What it does |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `CredentialProvider` | Protocol: `get_token(scope) -> str`. Any provider satisfies it. |
|
|
46
|
+
| `AuthPort` | Protocol for auth transport adapters (OAuth, LinkAuth, Device Flow, ...). |
|
|
47
|
+
| `AuthChallenge` | Exception raised when user interaction is needed (URL + code). |
|
|
48
|
+
| `AuthMixin` | Mixin for drivers -- catches auth challenges at the tool execution boundary. |
|
|
49
|
+
| `StaticProvider` | Simple provider: tokens from a dict or environment variables. |
|
|
50
|
+
|
|
51
|
+
## Quick start
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from mcs.auth.static import StaticProvider
|
|
55
|
+
|
|
56
|
+
# From a dict
|
|
57
|
+
provider = StaticProvider(tokens={"gmail": "ya29.xxx", "openai": "sk-xxx"})
|
|
58
|
+
token = provider.get_token("gmail")
|
|
59
|
+
|
|
60
|
+
# From environment variables (MCS_TOKEN_GMAIL, MCS_TOKEN_OPENAI, ...)
|
|
61
|
+
provider = StaticProvider()
|
|
62
|
+
token = provider.get_token("gmail")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## The big picture
|
|
66
|
+
|
|
67
|
+
Your agent calls `provider.get_token("gmail")`. Where that token comes from
|
|
68
|
+
is none of the agent's business:
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
CredentialProvider.get_token("gmail")
|
|
72
|
+
|
|
|
73
|
+
+-- StaticProvider (env vars, dicts)
|
|
74
|
+
+-- Auth0Provider (Token Vault exchange) --> mcs-auth-auth0
|
|
75
|
+
+-- OAuthProvider (browser login) --> mcs-auth-oauth
|
|
76
|
+
+-- LinkAuthProvider (device-flow broker) --> mcs-auth-linkauth
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Swap providers without touching agent code. Add new services without new
|
|
80
|
+
OAuth integrations. That's the power of a protocol-based auth layer.
|
|
81
|
+
|
|
82
|
+
## Links
|
|
83
|
+
|
|
84
|
+
- **Homepage:** <https://www.modelcontextstandard.io>
|
|
85
|
+
- **Source:** <https://github.com/modelcontextstandard/python-sdk>
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
Apache-2.0
|
mcs_auth-0.1.0/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# mcs-auth
|
|
2
|
+
|
|
3
|
+
The authentication backbone for the **Model Context Standard (MCS)**.
|
|
4
|
+
|
|
5
|
+
Stop wiring OAuth flows, API keys, and token refresh logic into every agent
|
|
6
|
+
you build. `mcs-auth` defines a universal `CredentialProvider` protocol --
|
|
7
|
+
one interface, any credential source. Your agent code never changes, no
|
|
8
|
+
matter how authentication works behind the scenes.
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install mcs-auth
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## What's inside
|
|
17
|
+
|
|
18
|
+
| Component | What it does |
|
|
19
|
+
|---|---|
|
|
20
|
+
| `CredentialProvider` | Protocol: `get_token(scope) -> str`. Any provider satisfies it. |
|
|
21
|
+
| `AuthPort` | Protocol for auth transport adapters (OAuth, LinkAuth, Device Flow, ...). |
|
|
22
|
+
| `AuthChallenge` | Exception raised when user interaction is needed (URL + code). |
|
|
23
|
+
| `AuthMixin` | Mixin for drivers -- catches auth challenges at the tool execution boundary. |
|
|
24
|
+
| `StaticProvider` | Simple provider: tokens from a dict or environment variables. |
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
from mcs.auth.static import StaticProvider
|
|
30
|
+
|
|
31
|
+
# From a dict
|
|
32
|
+
provider = StaticProvider(tokens={"gmail": "ya29.xxx", "openai": "sk-xxx"})
|
|
33
|
+
token = provider.get_token("gmail")
|
|
34
|
+
|
|
35
|
+
# From environment variables (MCS_TOKEN_GMAIL, MCS_TOKEN_OPENAI, ...)
|
|
36
|
+
provider = StaticProvider()
|
|
37
|
+
token = provider.get_token("gmail")
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## The big picture
|
|
41
|
+
|
|
42
|
+
Your agent calls `provider.get_token("gmail")`. Where that token comes from
|
|
43
|
+
is none of the agent's business:
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
CredentialProvider.get_token("gmail")
|
|
47
|
+
|
|
|
48
|
+
+-- StaticProvider (env vars, dicts)
|
|
49
|
+
+-- Auth0Provider (Token Vault exchange) --> mcs-auth-auth0
|
|
50
|
+
+-- OAuthProvider (browser login) --> mcs-auth-oauth
|
|
51
|
+
+-- LinkAuthProvider (device-flow broker) --> mcs-auth-linkauth
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Swap providers without touching agent code. Add new services without new
|
|
55
|
+
OAuth integrations. That's the power of a protocol-based auth layer.
|
|
56
|
+
|
|
57
|
+
## Links
|
|
58
|
+
|
|
59
|
+
- **Homepage:** <https://www.modelcontextstandard.io>
|
|
60
|
+
- **Source:** <https://github.com/modelcontextstandard/python-sdk>
|
|
61
|
+
|
|
62
|
+
## License
|
|
63
|
+
|
|
64
|
+
Apache-2.0
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=63", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "mcs-auth"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Credential provider abstraction for the Model Context Standard."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
keywords = ["mcs", "modelcontextstandard", "auth", "credentials", "oauth2", "token"]
|
|
13
|
+
authors = [{ name = "Danny Gerst", email = "danny@dannygerst.de" }]
|
|
14
|
+
license-files = ["LICENSE"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.9",
|
|
20
|
+
"Programming Language :: Python :: 3.10",
|
|
21
|
+
"Programming Language :: Python :: 3.11",
|
|
22
|
+
"Programming Language :: Python :: 3.12",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Topic :: Security",
|
|
25
|
+
"Topic :: Software Development :: Libraries",
|
|
26
|
+
"Typing :: Typed",
|
|
27
|
+
]
|
|
28
|
+
|
|
29
|
+
urls = {"Homepage" = "https://www.modelcontextstandard.io", "Source" = "https://github.com/modelcontextstandard/python-sdk"}
|
|
30
|
+
|
|
31
|
+
dependencies = []
|
|
32
|
+
|
|
33
|
+
[tool.setuptools.packages.find]
|
|
34
|
+
where = ["src"]
|
mcs_auth-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Authentication challenge -- raised when credentials are not yet available.
|
|
2
|
+
|
|
3
|
+
This exception is part of the lazy-auth pattern: a
|
|
4
|
+
``CredentialProvider`` raises ``AuthChallenge`` when it cannot supply a
|
|
5
|
+
token *yet* but has started an interactive flow (e.g. device
|
|
6
|
+
authorisation) that the end-user must complete first.
|
|
7
|
+
|
|
8
|
+
The ``AuthMixin`` (see ``mcs.auth.mixin``) catches this exception at
|
|
9
|
+
the ``execute_tool`` boundary and converts it into a structured tool
|
|
10
|
+
result that the LLM can present to the user.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class AuthChallenge(Exception):
|
|
17
|
+
"""Raised when credentials require user interaction before they become available.
|
|
18
|
+
|
|
19
|
+
Parameters
|
|
20
|
+
----------
|
|
21
|
+
message :
|
|
22
|
+
Human-readable description of what the user needs to do.
|
|
23
|
+
url :
|
|
24
|
+
Verification URL the user should open (e.g. device-flow URI).
|
|
25
|
+
code :
|
|
26
|
+
User code to enter at *url* (device-flow pattern).
|
|
27
|
+
scope :
|
|
28
|
+
The scope that triggered the challenge (e.g. ``"gmail"``).
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(
|
|
32
|
+
self,
|
|
33
|
+
message: str,
|
|
34
|
+
*,
|
|
35
|
+
url: str | None = None,
|
|
36
|
+
code: str | None = None,
|
|
37
|
+
scope: str | None = None,
|
|
38
|
+
) -> None:
|
|
39
|
+
self.url = url
|
|
40
|
+
self.code = code
|
|
41
|
+
self.scope = scope
|
|
42
|
+
super().__init__(message)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""AuthMixin -- intercepts authentication challenges at the tool-execution boundary.
|
|
2
|
+
|
|
3
|
+
This mixin is designed to be mixed into any ``DriverBase`` subclass.
|
|
4
|
+
When a tool execution raises ``AuthChallenge`` (because a
|
|
5
|
+
``CredentialProvider`` needs user interaction), the mixin catches the
|
|
6
|
+
exception and returns a structured JSON result instead of letting
|
|
7
|
+
``DriverBase`` treat it as a generic failure.
|
|
8
|
+
|
|
9
|
+
The LLM sees the result as a *successful* tool call whose content
|
|
10
|
+
describes the authentication action the user must take. This keeps
|
|
11
|
+
auth concerns completely outside of ``DriverBase`` (core).
|
|
12
|
+
|
|
13
|
+
Usage::
|
|
14
|
+
|
|
15
|
+
from mcs.auth.mixin import AuthMixin
|
|
16
|
+
from mcs.driver.core import DriverBase
|
|
17
|
+
|
|
18
|
+
class MyDriver(AuthMixin, DriverBase):
|
|
19
|
+
...
|
|
20
|
+
|
|
21
|
+
Python's MRO ensures ``AuthMixin.execute_tool`` wraps
|
|
22
|
+
``DriverBase.execute_tool`` (via ``super()``).
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
import json
|
|
28
|
+
from typing import Any
|
|
29
|
+
|
|
30
|
+
from .challenge import AuthChallenge
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
class AuthMixin:
|
|
34
|
+
"""Catches ``AuthChallenge`` from tool execution and converts it to a tool result.
|
|
35
|
+
|
|
36
|
+
The mixin overrides ``execute_tool`` so that ``DriverBase.process_llm_response``
|
|
37
|
+
receives a normal result string (not an exception), allowing the LLM to present
|
|
38
|
+
the authentication instructions to the user naturally.
|
|
39
|
+
"""
|
|
40
|
+
|
|
41
|
+
def execute_tool(self, tool_name: str, arguments: dict[str, Any]) -> Any:
|
|
42
|
+
try:
|
|
43
|
+
return super().execute_tool(tool_name, arguments) # type: ignore[misc]
|
|
44
|
+
except AuthChallenge as exc:
|
|
45
|
+
payload: dict[str, Any] = {
|
|
46
|
+
"auth_required": True,
|
|
47
|
+
"message": str(exc),
|
|
48
|
+
}
|
|
49
|
+
if exc.url:
|
|
50
|
+
payload["url"] = exc.url
|
|
51
|
+
if exc.code:
|
|
52
|
+
payload["code"] = exc.code
|
|
53
|
+
if exc.scope:
|
|
54
|
+
payload["scope"] = exc.scope
|
|
55
|
+
return json.dumps(payload)
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""Authentication port abstractions for MCS.
|
|
2
|
+
|
|
3
|
+
Defines the contract that any auth transport adapter must satisfy.
|
|
4
|
+
Adapters fulfil this protocol through structural subtyping -- they do
|
|
5
|
+
**not** need to import or inherit from this module.
|
|
6
|
+
|
|
7
|
+
This follows the same pattern as ``MailboxPort`` and ``HttpPort``:
|
|
8
|
+
the driver/provider depends on the protocol, not on a concrete adapter.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
from typing import Protocol, runtime_checkable
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@runtime_checkable
|
|
17
|
+
class AuthPort(Protocol):
|
|
18
|
+
"""Transport abstraction for obtaining authentication tokens.
|
|
19
|
+
|
|
20
|
+
An ``AuthPort`` adapter handles the actual mechanism for acquiring a
|
|
21
|
+
token -- OAuth Authorization Code Flow, LinkAuth device-flow broker,
|
|
22
|
+
environment variables, or any other source.
|
|
23
|
+
|
|
24
|
+
The provider (e.g. ``Auth0Provider``) calls ``authenticate`` to get
|
|
25
|
+
the raw token, then applies any additional steps (like Token Vault
|
|
26
|
+
exchange) on top.
|
|
27
|
+
|
|
28
|
+
Implementations **may** raise ``AuthChallenge`` when user interaction
|
|
29
|
+
is required (e.g. opening a URL, entering a code).
|
|
30
|
+
"""
|
|
31
|
+
|
|
32
|
+
def authenticate(self, scope: str) -> str:
|
|
33
|
+
"""Return a raw token (e.g. refresh token, access token, API key) for *scope*.
|
|
34
|
+
|
|
35
|
+
Parameters
|
|
36
|
+
----------
|
|
37
|
+
scope :
|
|
38
|
+
Identifier for the requested credential (e.g. ``"gmail"``,
|
|
39
|
+
``"slack"``, ``"openai"``).
|
|
40
|
+
|
|
41
|
+
Returns
|
|
42
|
+
-------
|
|
43
|
+
str
|
|
44
|
+
The token string.
|
|
45
|
+
|
|
46
|
+
Raises
|
|
47
|
+
------
|
|
48
|
+
AuthChallenge
|
|
49
|
+
When user interaction is needed before the token can be
|
|
50
|
+
obtained.
|
|
51
|
+
LookupError
|
|
52
|
+
When no credential is available and no interactive flow
|
|
53
|
+
can be started.
|
|
54
|
+
RuntimeError
|
|
55
|
+
When the auth flow fails (network, config, etc.).
|
|
56
|
+
"""
|
|
57
|
+
...
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Credential provider abstraction for MCS.
|
|
2
|
+
|
|
3
|
+
Defines the contract that any credential provider must satisfy.
|
|
4
|
+
Providers fulfil this protocol through structural subtyping -- they do
|
|
5
|
+
**not** need to import or inherit from this module.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Protocol, runtime_checkable
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@runtime_checkable
|
|
14
|
+
class CredentialProvider(Protocol):
|
|
15
|
+
"""Universal contract for retrieving credentials.
|
|
16
|
+
|
|
17
|
+
A credential provider returns an access token (or API key) for a
|
|
18
|
+
given *scope*. Scopes are simple strings that identify what the
|
|
19
|
+
token grants access to -- e.g. ``"gmail"``, ``"slack"``,
|
|
20
|
+
``"https://api.example.com"``.
|
|
21
|
+
|
|
22
|
+
Implementations may fetch tokens from Auth0 Token Vault, a local
|
|
23
|
+
keyring, environment variables, a static dict, or any other source.
|
|
24
|
+
|
|
25
|
+
The provider is intentionally **synchronous**. Async callers can
|
|
26
|
+
wrap it in ``asyncio.to_thread``.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
def get_token(self, scope: str) -> str:
|
|
30
|
+
"""Return a valid access token / API key for *scope*.
|
|
31
|
+
|
|
32
|
+
Implementations should handle caching and refresh internally
|
|
33
|
+
so that callers always receive a usable token.
|
|
34
|
+
|
|
35
|
+
Raises
|
|
36
|
+
------
|
|
37
|
+
LookupError
|
|
38
|
+
When no credential is available for the requested scope.
|
|
39
|
+
RuntimeError
|
|
40
|
+
When the underlying auth flow fails (network, config, ...).
|
|
41
|
+
"""
|
|
42
|
+
...
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"""Static credential provider -- tokens from a dict or environment variables.
|
|
2
|
+
|
|
3
|
+
Useful for local development, testing, and simple deployments where
|
|
4
|
+
tokens are known upfront or stored in environment variables.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import os
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class StaticProvider:
|
|
13
|
+
"""Credential provider backed by a plain dictionary.
|
|
14
|
+
|
|
15
|
+
Parameters
|
|
16
|
+
----------
|
|
17
|
+
tokens :
|
|
18
|
+
Mapping of scope → token value. When a scope is not found
|
|
19
|
+
in *tokens*, the provider falls back to the environment
|
|
20
|
+
variable ``MCS_TOKEN_<SCOPE>`` (upper-cased, hyphens replaced
|
|
21
|
+
with underscores).
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
def __init__(self, tokens: dict[str, str] | None = None) -> None:
|
|
25
|
+
self._tokens: dict[str, str] = dict(tokens or {})
|
|
26
|
+
|
|
27
|
+
def get_token(self, scope: str) -> str:
|
|
28
|
+
"""Return a token for *scope* from the dict or environment."""
|
|
29
|
+
if scope in self._tokens:
|
|
30
|
+
return self._tokens[scope]
|
|
31
|
+
|
|
32
|
+
env_key = f"MCS_TOKEN_{scope.upper().replace('-', '_').replace('.', '_')}"
|
|
33
|
+
env_val = os.environ.get(env_key)
|
|
34
|
+
if env_val:
|
|
35
|
+
return env_val
|
|
36
|
+
|
|
37
|
+
raise LookupError(
|
|
38
|
+
f"No credential for scope {scope!r}. "
|
|
39
|
+
f"Provide it via StaticProvider(tokens={{...}}) or set {env_key}."
|
|
40
|
+
)
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: mcs-auth
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Credential provider abstraction for the Model Context Standard.
|
|
5
|
+
Author-email: Danny Gerst <danny@dannygerst.de>
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://www.modelcontextstandard.io
|
|
8
|
+
Project-URL: Source, https://github.com/modelcontextstandard/python-sdk
|
|
9
|
+
Keywords: mcs,modelcontextstandard,auth,credentials,oauth2,token
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Security
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
20
|
+
Classifier: Typing :: Typed
|
|
21
|
+
Requires-Python: >=3.9
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
License-File: LICENSE
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
|
|
26
|
+
# mcs-auth
|
|
27
|
+
|
|
28
|
+
The authentication backbone for the **Model Context Standard (MCS)**.
|
|
29
|
+
|
|
30
|
+
Stop wiring OAuth flows, API keys, and token refresh logic into every agent
|
|
31
|
+
you build. `mcs-auth` defines a universal `CredentialProvider` protocol --
|
|
32
|
+
one interface, any credential source. Your agent code never changes, no
|
|
33
|
+
matter how authentication works behind the scenes.
|
|
34
|
+
|
|
35
|
+
## Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install mcs-auth
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## What's inside
|
|
42
|
+
|
|
43
|
+
| Component | What it does |
|
|
44
|
+
|---|---|
|
|
45
|
+
| `CredentialProvider` | Protocol: `get_token(scope) -> str`. Any provider satisfies it. |
|
|
46
|
+
| `AuthPort` | Protocol for auth transport adapters (OAuth, LinkAuth, Device Flow, ...). |
|
|
47
|
+
| `AuthChallenge` | Exception raised when user interaction is needed (URL + code). |
|
|
48
|
+
| `AuthMixin` | Mixin for drivers -- catches auth challenges at the tool execution boundary. |
|
|
49
|
+
| `StaticProvider` | Simple provider: tokens from a dict or environment variables. |
|
|
50
|
+
|
|
51
|
+
## Quick start
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
from mcs.auth.static import StaticProvider
|
|
55
|
+
|
|
56
|
+
# From a dict
|
|
57
|
+
provider = StaticProvider(tokens={"gmail": "ya29.xxx", "openai": "sk-xxx"})
|
|
58
|
+
token = provider.get_token("gmail")
|
|
59
|
+
|
|
60
|
+
# From environment variables (MCS_TOKEN_GMAIL, MCS_TOKEN_OPENAI, ...)
|
|
61
|
+
provider = StaticProvider()
|
|
62
|
+
token = provider.get_token("gmail")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## The big picture
|
|
66
|
+
|
|
67
|
+
Your agent calls `provider.get_token("gmail")`. Where that token comes from
|
|
68
|
+
is none of the agent's business:
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
CredentialProvider.get_token("gmail")
|
|
72
|
+
|
|
|
73
|
+
+-- StaticProvider (env vars, dicts)
|
|
74
|
+
+-- Auth0Provider (Token Vault exchange) --> mcs-auth-auth0
|
|
75
|
+
+-- OAuthProvider (browser login) --> mcs-auth-oauth
|
|
76
|
+
+-- LinkAuthProvider (device-flow broker) --> mcs-auth-linkauth
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Swap providers without touching agent code. Add new services without new
|
|
80
|
+
OAuth integrations. That's the power of a protocol-based auth layer.
|
|
81
|
+
|
|
82
|
+
## Links
|
|
83
|
+
|
|
84
|
+
- **Homepage:** <https://www.modelcontextstandard.io>
|
|
85
|
+
- **Source:** <https://github.com/modelcontextstandard/python-sdk>
|
|
86
|
+
|
|
87
|
+
## License
|
|
88
|
+
|
|
89
|
+
Apache-2.0
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
src/mcs/auth/challenge.py
|
|
5
|
+
src/mcs/auth/mixin.py
|
|
6
|
+
src/mcs/auth/ports.py
|
|
7
|
+
src/mcs/auth/provider.py
|
|
8
|
+
src/mcs/auth/static.py
|
|
9
|
+
src/mcs_auth.egg-info/PKG-INFO
|
|
10
|
+
src/mcs_auth.egg-info/SOURCES.txt
|
|
11
|
+
src/mcs_auth.egg-info/dependency_links.txt
|
|
12
|
+
src/mcs_auth.egg-info/top_level.txt
|
|
13
|
+
tests/test_auth_mixin.py
|
|
14
|
+
tests/test_static_provider.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
mcs
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""Tests for AuthChallenge and AuthMixin."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
import pytest
|
|
9
|
+
|
|
10
|
+
from mcs.auth.challenge import AuthChallenge
|
|
11
|
+
from mcs.auth.mixin import AuthMixin
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TestAuthChallenge:
|
|
15
|
+
|
|
16
|
+
def test_basic_attributes(self):
|
|
17
|
+
exc = AuthChallenge(
|
|
18
|
+
"Please login",
|
|
19
|
+
url="https://example.com/activate",
|
|
20
|
+
code="ABCD-1234",
|
|
21
|
+
scope="gmail",
|
|
22
|
+
)
|
|
23
|
+
assert str(exc) == "Please login"
|
|
24
|
+
assert exc.url == "https://example.com/activate"
|
|
25
|
+
assert exc.code == "ABCD-1234"
|
|
26
|
+
assert exc.scope == "gmail"
|
|
27
|
+
|
|
28
|
+
def test_defaults_to_none(self):
|
|
29
|
+
exc = AuthChallenge("login needed")
|
|
30
|
+
assert exc.url is None
|
|
31
|
+
assert exc.code is None
|
|
32
|
+
assert exc.scope is None
|
|
33
|
+
|
|
34
|
+
def test_is_exception(self):
|
|
35
|
+
assert issubclass(AuthChallenge, Exception)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class FakeToolDriver:
|
|
39
|
+
"""Simulates a DriverBase with execute_tool."""
|
|
40
|
+
|
|
41
|
+
def __init__(self, result: Any = None, error: Exception | None = None):
|
|
42
|
+
self._result = result
|
|
43
|
+
self._error = error
|
|
44
|
+
|
|
45
|
+
def execute_tool(self, tool_name: str, arguments: dict[str, Any]) -> Any:
|
|
46
|
+
if self._error:
|
|
47
|
+
raise self._error
|
|
48
|
+
return self._result
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class MixedDriver(AuthMixin, FakeToolDriver):
|
|
52
|
+
"""AuthMixin + FakeToolDriver via MRO."""
|
|
53
|
+
pass
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class TestAuthMixin:
|
|
57
|
+
|
|
58
|
+
def test_normal_execution_passes_through(self):
|
|
59
|
+
driver = MixedDriver(result='{"messages": []}')
|
|
60
|
+
result = driver.execute_tool("list_messages", {})
|
|
61
|
+
assert result == '{"messages": []}'
|
|
62
|
+
|
|
63
|
+
def test_auth_challenge_converted_to_json(self):
|
|
64
|
+
challenge = AuthChallenge(
|
|
65
|
+
"Please authenticate",
|
|
66
|
+
url="https://auth0.com/activate",
|
|
67
|
+
code="WXYZ-5678",
|
|
68
|
+
scope="gmail",
|
|
69
|
+
)
|
|
70
|
+
driver = MixedDriver(error=challenge)
|
|
71
|
+
result = driver.execute_tool("list_messages", {})
|
|
72
|
+
data = json.loads(result)
|
|
73
|
+
|
|
74
|
+
assert data["auth_required"] is True
|
|
75
|
+
assert data["message"] == "Please authenticate"
|
|
76
|
+
assert data["url"] == "https://auth0.com/activate"
|
|
77
|
+
assert data["code"] == "WXYZ-5678"
|
|
78
|
+
assert data["scope"] == "gmail"
|
|
79
|
+
|
|
80
|
+
def test_auth_challenge_without_optional_fields(self):
|
|
81
|
+
challenge = AuthChallenge("API key needed")
|
|
82
|
+
driver = MixedDriver(error=challenge)
|
|
83
|
+
result = driver.execute_tool("some_tool", {})
|
|
84
|
+
data = json.loads(result)
|
|
85
|
+
|
|
86
|
+
assert data["auth_required"] is True
|
|
87
|
+
assert data["message"] == "API key needed"
|
|
88
|
+
assert "url" not in data
|
|
89
|
+
assert "code" not in data
|
|
90
|
+
assert "scope" not in data
|
|
91
|
+
|
|
92
|
+
def test_other_exceptions_propagate(self):
|
|
93
|
+
driver = MixedDriver(error=ValueError("something broke"))
|
|
94
|
+
with pytest.raises(ValueError, match="something broke"):
|
|
95
|
+
driver.execute_tool("list_messages", {})
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Tests for StaticProvider."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
|
|
7
|
+
import pytest
|
|
8
|
+
|
|
9
|
+
from mcs.auth.provider import CredentialProvider
|
|
10
|
+
from mcs.auth.static import StaticProvider
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class TestStaticProvider:
|
|
14
|
+
|
|
15
|
+
def test_satisfies_protocol(self):
|
|
16
|
+
provider = StaticProvider({"gmail": "tok123"})
|
|
17
|
+
assert isinstance(provider, CredentialProvider)
|
|
18
|
+
|
|
19
|
+
def test_get_token_from_dict(self):
|
|
20
|
+
provider = StaticProvider({"gmail": "tok-gmail", "slack": "tok-slack"})
|
|
21
|
+
assert provider.get_token("gmail") == "tok-gmail"
|
|
22
|
+
assert provider.get_token("slack") == "tok-slack"
|
|
23
|
+
|
|
24
|
+
def test_get_token_from_env(self, monkeypatch: pytest.MonkeyPatch):
|
|
25
|
+
monkeypatch.setenv("MCS_TOKEN_GITHUB", "tok-gh")
|
|
26
|
+
provider = StaticProvider()
|
|
27
|
+
assert provider.get_token("github") == "tok-gh"
|
|
28
|
+
|
|
29
|
+
def test_get_token_env_normalisation(self, monkeypatch: pytest.MonkeyPatch):
|
|
30
|
+
monkeypatch.setenv("MCS_TOKEN_MY_API", "tok-api")
|
|
31
|
+
provider = StaticProvider()
|
|
32
|
+
assert provider.get_token("my-api") == "tok-api"
|
|
33
|
+
|
|
34
|
+
def test_dict_takes_precedence_over_env(self, monkeypatch: pytest.MonkeyPatch):
|
|
35
|
+
monkeypatch.setenv("MCS_TOKEN_GMAIL", "env-token")
|
|
36
|
+
provider = StaticProvider({"gmail": "dict-token"})
|
|
37
|
+
assert provider.get_token("gmail") == "dict-token"
|
|
38
|
+
|
|
39
|
+
def test_missing_scope_raises_lookup_error(self):
|
|
40
|
+
provider = StaticProvider()
|
|
41
|
+
with pytest.raises(LookupError, match="No credential for scope 'unknown'"):
|
|
42
|
+
provider.get_token("unknown")
|
|
43
|
+
|
|
44
|
+
def test_empty_provider(self):
|
|
45
|
+
provider = StaticProvider()
|
|
46
|
+
with pytest.raises(LookupError):
|
|
47
|
+
provider.get_token("anything")
|