streamlit-nightly 1.41.2.dev20250117__py2.py3-none-any.whl → 1.41.2.dev20250124__py2.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.
- streamlit/config.py +14 -0
- streamlit/elements/vega_charts.py +19 -5
- streamlit/material_icon_names.py +1 -1
- streamlit/runtime/runtime.py +8 -3
- streamlit/runtime/state/query_params.py +1 -1
- streamlit/runtime/state/query_params_proxy.py +14 -4
- streamlit/static/index.html +2 -2
- streamlit/static/static/css/{index.BWGEWL3m.css → index.mUTQuMqR.css} +1 -1
- streamlit/static/static/js/{FileDownload.esm.BUw5ikQY.js → FileDownload.esm.C1QvS8Zm.js} +1 -1
- streamlit/static/static/js/{FormClearHelper.Bvmaiutv.js → FormClearHelper.mT4-5rFn.js} +1 -1
- streamlit/static/static/js/{Hooks.DcERo8tB.js → Hooks.CVNEuaGG.js} +1 -1
- streamlit/static/static/js/{InputInstructions.BupGmSrJ.js → InputInstructions.BCvAGBeC.js} +1 -1
- streamlit/static/static/js/ProgressBar.CcQcYD9u.js +2 -0
- streamlit/static/static/js/{RenderInPortalIfExists.BhbPC-G8.js → RenderInPortalIfExists.DHDG9PHn.js} +1 -1
- streamlit/static/static/js/Toolbar.yTE_O6B7.js +1 -0
- streamlit/static/static/js/{base-input.BBtHVXa2.js → base-input.CQPY9_oN.js} +4 -4
- streamlit/static/static/js/createSuper.DE47Tkz4.js +1 -0
- streamlit/static/static/js/data-grid-overlay-editor.5JEQwfzp.js +1 -0
- streamlit/static/static/js/{downloader.4xvEoIbd.js → downloader.CX7_KkfB.js} +1 -1
- streamlit/static/static/js/{es6.DmlLpYMO.js → es6.Be2vwxoI.js} +2 -2
- streamlit/static/static/js/{iframeResizer.contentWindow.CgYHddZ1.js → iframeResizer.contentWindow.CFHofqC-.js} +1 -1
- streamlit/static/static/js/index.0OeiPvr3.js +1 -0
- streamlit/static/static/js/{index.C8nPrwl-.js → index.1GBg_Cdb.js} +1 -1
- streamlit/static/static/js/index.4nNgvhbk.js +4 -0
- streamlit/static/static/js/index.5F9_LJ-9.js +1 -0
- streamlit/static/static/js/{index.C4Hwzvpq.js → index.6v5ZgUAy.js} +1 -1
- streamlit/static/static/js/index.8tVXPrLX.js +1 -0
- streamlit/static/static/js/index.AExANgn1.js +1 -0
- streamlit/static/static/js/index.AXOgS1NM.js +1 -0
- streamlit/static/static/js/index.B-xzXPZE.js +3 -0
- streamlit/static/static/js/index.B0pfFJGU.js +1 -0
- streamlit/static/static/js/{index.BaskQ92_.js → index.BBjf7kH1.js} +1 -1
- streamlit/static/static/js/{index.CsdGlifB.js → index.BGICDmL0.js} +13 -13
- streamlit/static/static/js/{index.DcY4XgAF.js → index.BOeLQ18h.js} +1 -1
- streamlit/static/static/js/{index.DeeIZCGU.js → index.BUgJRfqp.js} +3 -3
- streamlit/static/static/js/{index.DZdyNQo1.js → index.BpeIAypN.js} +1 -1
- streamlit/static/static/js/{index.CkCtIbw0.js → index.C0ZNaKGF.js} +1 -1
- streamlit/static/static/js/index.C3eR9AQ5.js +1 -0
- streamlit/static/static/js/index.CCmrDm8Z.js +2 -0
- streamlit/static/static/js/index.CHuo89tL.js +1 -0
- streamlit/static/static/js/index.Cbi_d9ak.js +197 -0
- streamlit/static/static/js/{index.g24MGpB6.js → index.Cg7T4wJt.js} +3 -3
- streamlit/static/static/js/index.Ci3iebpl.js +1 -0
- streamlit/static/static/js/index.CjsaBedq.js +1 -0
- streamlit/static/static/js/{index.CrcobIb0.js → index.CvqaNor_.js} +131 -120
- streamlit/static/static/js/{index.Bu8uxdTh.js → index.D0lxtOCO.js} +2 -2
- streamlit/static/static/js/{index.DysCLUsb.js → index.D1AD4NsW.js} +1 -1
- streamlit/static/static/js/{index.61noqmIB.js → index.DLjk_wlB.js} +1 -1
- streamlit/static/static/js/{index.rOJcC1R3.js → index.DNDhYAPI.js} +2 -2
- streamlit/static/static/js/index.DY6666R7.js +1 -0
- streamlit/static/static/js/{index.DH9CvsgQ.js → index.Dkr_c_9x.js} +51 -51
- streamlit/static/static/js/{index.DKi-ElEv.js → index.Hhv6gSq2.js} +1 -1
- streamlit/static/static/js/{index.CjxOLcYo.js → index.OM83ZHKg.js} +1 -1
- streamlit/static/static/js/index.SLleoa9s.js +1 -0
- streamlit/static/static/js/{index.CC_t9mT8.js → index.XCwDes79.js} +1 -1
- streamlit/static/static/js/{index.Bq6R9vFh.js → index.a6pesEXT.js} +1 -1
- streamlit/static/static/js/{index.CAZxiea2.js → index.er3Zfn3e.js} +2 -2
- streamlit/static/static/js/{index.CeKudMLQ.js → index.mtSGfsND.js} +1 -1
- streamlit/static/static/js/{input.BIth4Mda.js → input.B07wSbwn.js} +1 -1
- streamlit/static/static/js/{memory.C0ticMnk.js → memory.CC_p93jh.js} +1 -1
- streamlit/static/static/js/{mergeWith.CnJI40Ol.js → mergeWith.ivc75cD1.js} +1 -1
- streamlit/static/static/js/number-overlay-editor.Db2Be6nq.js +9 -0
- streamlit/static/static/js/possibleConstructorReturn.BNprLGNF.js +1 -0
- streamlit/static/static/js/{sandbox.D1ghBIHY.js → sandbox.BlG3HhHL.js} +1 -1
- streamlit/static/static/js/{textarea.C1RJDJe0.js → textarea.Bz6Z-kmO.js} +2 -2
- streamlit/static/static/js/{timepicker.CmttWl-Y.js → timepicker.BMSb5NlP.js} +3 -3
- streamlit/static/static/js/toConsumableArray.uYLXBIlD.js +3 -0
- streamlit/static/static/js/uniqueId.BdisvZXg.js +1 -0
- streamlit/static/static/js/{useBasicWidgetState.BB9oQkjJ.js → useBasicWidgetState.BJFGEQDL.js} +1 -1
- streamlit/static/static/js/{useOnInputChange.DldtvoCQ.js → useOnInputChange.BmSN_ACz.js} +1 -1
- streamlit/static/static/js/withFullScreenWrapper.CbOOMX5j.js +1 -0
- streamlit/static/static/media/MaterialSymbols-Rounded.DzyB5T7Y.woff2 +0 -0
- streamlit/user_info.py +364 -11
- {streamlit_nightly-1.41.2.dev20250117.dist-info → streamlit_nightly-1.41.2.dev20250124.dist-info}/METADATA +1 -1
- {streamlit_nightly-1.41.2.dev20250117.dist-info → streamlit_nightly-1.41.2.dev20250124.dist-info}/RECORD +81 -81
- streamlit/static/static/js/ProgressBar.CTBNJVpb.js +0 -2
- streamlit/static/static/js/Toolbar.Dw79Vekz.js +0 -1
- streamlit/static/static/js/createSuper.BBR-BbJr.js +0 -1
- streamlit/static/static/js/data-grid-overlay-editor.DuZabixr.js +0 -1
- streamlit/static/static/js/getPrototypeOf.M3x98UQ7.js +0 -1
- streamlit/static/static/js/index.27TXU2hu.js +0 -1
- streamlit/static/static/js/index.AoUAN-9W.js +0 -1
- streamlit/static/static/js/index.B1KjaM9R.js +0 -1
- streamlit/static/static/js/index.BXejhz8S.js +0 -197
- streamlit/static/static/js/index.BYyuymTq.js +0 -4
- streamlit/static/static/js/index.BtxHQDnZ.js +0 -1
- streamlit/static/static/js/index.C-0rgxAG.js +0 -1
- streamlit/static/static/js/index.C21AcM0r.js +0 -1
- streamlit/static/static/js/index.CuzQoPgT.js +0 -1
- streamlit/static/static/js/index.DqjAk5qg.js +0 -3
- streamlit/static/static/js/index.Dva5NuFG.js +0 -1
- streamlit/static/static/js/index.DvfPGXer.js +0 -1
- streamlit/static/static/js/index.PWzpo-hC.js +0 -2
- streamlit/static/static/js/index.STXqYP7Q.js +0 -1
- streamlit/static/static/js/index.WSrEkxsE.js +0 -1
- streamlit/static/static/js/index.tjVAqGRi.js +0 -1
- streamlit/static/static/js/number-overlay-editor.B4oKK-_Y.js +0 -9
- streamlit/static/static/js/slicedToArray.C1s2cVDA.js +0 -2
- streamlit/static/static/js/uniqueId.BT1SAZF-.js +0 -1
- streamlit/static/static/js/withFullScreenWrapper.CWPfcXAP.js +0 -1
- streamlit/static/static/media/MaterialSymbols-Rounded.MYSe4dsi.woff2 +0 -0
- /streamlit/static/static/css/{index.B26BQfSF.css → index.Bmkmz40k.css} +0 -0
- /streamlit/static/static/css/{index.CG16XVnL.css → index.DzuxGC_t.css} +0 -0
- {streamlit_nightly-1.41.2.dev20250117.data → streamlit_nightly-1.41.2.dev20250124.data}/scripts/streamlit.cmd +0 -0
- {streamlit_nightly-1.41.2.dev20250117.dist-info → streamlit_nightly-1.41.2.dev20250124.dist-info}/WHEEL +0 -0
- {streamlit_nightly-1.41.2.dev20250117.dist-info → streamlit_nightly-1.41.2.dev20250124.dist-info}/entry_points.txt +0 -0
- {streamlit_nightly-1.41.2.dev20250117.dist-info → streamlit_nightly-1.41.2.dev20250124.dist-info}/top_level.txt +0 -0
streamlit/user_info.py
CHANGED
@@ -48,14 +48,229 @@ AUTH_LOGOUT_ENDPOINT: Final = "/auth/logout"
|
|
48
48
|
|
49
49
|
@gather_metrics("login")
|
50
50
|
def login(provider: str | None = None) -> None:
|
51
|
-
"""Initiate the login for the given provider.
|
51
|
+
"""Initiate the login flow for the given provider.
|
52
|
+
|
53
|
+
This command redirects the user to an OpenID Connect (OIDC) provider. After
|
54
|
+
the user authenticates their identity, they are redirected back to the
|
55
|
+
home page of your app. Streamlit stores a cookie with the user's identity
|
56
|
+
information in the user's browser . You can access the identity information
|
57
|
+
through |st.experimental_user|_. Call ``st.logout()`` to remove the cookie
|
58
|
+
and start a new session.
|
59
|
+
|
60
|
+
You can use any OIDC provider, including Google, Microsoft, Okta, and more.
|
61
|
+
You must configure the provider through secrets management. Although OIDC
|
62
|
+
is an extension of OAuth 2.0, you can't use generic OAuth providers.
|
63
|
+
Streamlit parses the user's identity token and surfaces its attributes in
|
64
|
+
``st.experimental_user``. If the provider returns an access token, that
|
65
|
+
token is ignored. Therefore, this command will not allow your app to act on
|
66
|
+
behalf of a user in a secure system.
|
67
|
+
|
68
|
+
For all providers, there are two shared settings, ``redirect_uri`` and
|
69
|
+
``cookie_secret``, which you must specify in an ``[auth]`` dictionary
|
70
|
+
in ``secrets.toml``. Other settings must be defined as described in the
|
71
|
+
``provider`` parameter.
|
72
|
+
|
73
|
+
- ``redirect_uri`` is your app's absolute URL with the pathname
|
74
|
+
``oauth2callback``. For local development using the default port, this is
|
75
|
+
``http://localhost:8501/oauth2callback``.
|
76
|
+
- ``cookie_secret`` should be a strong, randomly generated secret.
|
77
|
+
|
78
|
+
In addition to the shared settings, the following settings are required:
|
79
|
+
|
80
|
+
- ``client_id``
|
81
|
+
- ``client_secret``
|
82
|
+
- ``server_metadata_url``
|
83
|
+
|
84
|
+
For a complete list of OIDC parameters, see `OpenID Connect Core
|
85
|
+
<https://openid.net/specs/openid-connect-core-1_0.html#AuthRequest>`_ and
|
86
|
+
your provider's documentation. By default, Streamlit sets
|
87
|
+
``scope="openid profile email"`` and ``prompt="select_account"``. You can
|
88
|
+
change these and other OIDC parameters by passing a dictionary of settings
|
89
|
+
to ``client_kwargs``. ``state`` and ``nonce``, which are used for
|
90
|
+
security, are handled automatically and don't need to be specified. For
|
91
|
+
more information, see Example 4.
|
92
|
+
|
93
|
+
.. Important::
|
94
|
+
- You must install ``Authlib>=1.3.2`` to use this command.
|
95
|
+
- Your authentication configuration is dependent on your host location.
|
96
|
+
When you deploy your app, remember to update your ``redirect_uri``
|
97
|
+
within your app and your provider.
|
98
|
+
- All URLs declared in the settings must be absolute (i.e., begin with
|
99
|
+
``http://`` or ``https://``).
|
100
|
+
- Streamlit automatically enables CORS and XSRF protection when you
|
101
|
+
configure authentication in ``secrets.toml``. This takes precedence
|
102
|
+
over configuration options in ``config.toml``.
|
103
|
+
- If a user is logged into your app and opens a new tab in the same
|
104
|
+
browser, they will automatically be logged in to the new session with
|
105
|
+
the same account.
|
106
|
+
- If a user closes your app without logging out, the identity cookie
|
107
|
+
will expire after 30 days.
|
108
|
+
- For security reasons, authentication is not supported for embedded
|
109
|
+
apps.
|
110
|
+
|
111
|
+
.. |st.experimental_user| replace:: ``st.experimental_user``
|
112
|
+
.. _st.experimental_user: https://docs.streamlit.io/develop/api-reference/utilities/st.experimental_user
|
52
113
|
|
53
114
|
Parameters
|
54
115
|
----------
|
55
|
-
provider
|
56
|
-
The provider to use for login.
|
57
|
-
|
58
|
-
If
|
116
|
+
provider: str or None
|
117
|
+
The name of your provider configuration to use for login.
|
118
|
+
|
119
|
+
If ``provider`` is ``None`` (default), Streamlit will use all settings
|
120
|
+
in the ``[auth]`` dictionary within your app's ``secrets.toml`` file.
|
121
|
+
Otherwise, use an ``[auth.{provider}]`` dictionary for the named
|
122
|
+
provider, as shown in the examples that follow. When you pass a string
|
123
|
+
to ``provider``, Streamlit will use ``redirect_uri`` and
|
124
|
+
``cookie_secret``, while ignoring any other values in the ``[auth]``
|
125
|
+
dictionary.
|
126
|
+
|
127
|
+
Examples
|
128
|
+
--------
|
129
|
+
|
130
|
+
**Example 1: Use an unnamed default identity provider**
|
131
|
+
|
132
|
+
If you do not specify a name for your provider, specify all settings within
|
133
|
+
the ``[auth]`` dictionary of your ``secrets.toml`` file. The following
|
134
|
+
example configures Google as the default provider. For information about
|
135
|
+
using OIDC with Google, see `Google Identity
|
136
|
+
<https://developers.google.com/identity/openid-connect/openid-connect>`_.
|
137
|
+
|
138
|
+
``.streamlit/secrets.toml``:
|
139
|
+
|
140
|
+
>>> [auth]
|
141
|
+
>>> redirect_uri = "http://localhost:8501/oauth2callback"
|
142
|
+
>>> cookie_secret = "xxx"
|
143
|
+
>>> client_id = "xxx"
|
144
|
+
>>> client_secret = "xxx"
|
145
|
+
>>> server_metadata_url = (
|
146
|
+
... "https://accounts.google.com/.well-known/openid-configuration"
|
147
|
+
... )
|
148
|
+
|
149
|
+
Your app code:
|
150
|
+
|
151
|
+
>>> import streamlit as st
|
152
|
+
>>>
|
153
|
+
>>> if not st.experimental_user.is_logged_in:
|
154
|
+
>>> if st.button("Log in"):
|
155
|
+
>>> st.login()
|
156
|
+
>>> else:
|
157
|
+
>>> if st.button("Log out"):
|
158
|
+
>>> st.logout()
|
159
|
+
>>> st.write(f"Hello, {st.experimental_user.name}!")
|
160
|
+
|
161
|
+
**Example 2: Use a named identity provider**
|
162
|
+
|
163
|
+
If you specify a name for your provider, save the shared settings in the
|
164
|
+
``[auth]`` dictionary of your ``secrets.toml`` file, and save the other
|
165
|
+
settings in an ``[auth.{provider}]`` dictionary, where ``{provider}`` is
|
166
|
+
the name of your provider. The following example configures Microsoft as
|
167
|
+
the provider. The example uses ``provider="microsoft"``, but you can use
|
168
|
+
any name. This name is internal to Streamlit and is used to match the login
|
169
|
+
command to its configuration. For information about using OIDC with
|
170
|
+
Microsoft, see `Microsoft Entra ID
|
171
|
+
<https://learn.microsoft.com/en-us/power-pages/security/authentication/openid-settings>`_.
|
172
|
+
To configure your ``{tenant}`` value in ``server_metadata_url``, see
|
173
|
+
`Microsoft identity platform
|
174
|
+
<https://learn.microsoft.com/en-us/entra/identity-platform/v2-protocols-oidc#find-your-apps-openid-configuration-document-uri>`_.
|
175
|
+
|
176
|
+
``.streamlit/secrets.toml``:
|
177
|
+
|
178
|
+
>>> [auth]
|
179
|
+
>>> redirect_uri = "http://localhost:8501/oauth2callback"
|
180
|
+
>>> cookie_secret = "xxx"
|
181
|
+
>>>
|
182
|
+
>>> [auth.microsoft]
|
183
|
+
>>> client_id = "xxx"
|
184
|
+
>>> client_secret = "xxx"
|
185
|
+
>>> server_metadata_url = "https://login.microsoftonline.com/{tenant}/v2.0/.well-known/openid-configuration"
|
186
|
+
|
187
|
+
Your app code:
|
188
|
+
|
189
|
+
>>> import streamlit as st
|
190
|
+
>>>
|
191
|
+
>>> if not st.experimental_user.is_logged_in:
|
192
|
+
>>> st.login("microsoft")
|
193
|
+
>>> else:
|
194
|
+
>>> st.write(f"Hello, {st.experimental_user.name}!")
|
195
|
+
|
196
|
+
**Example 3: Use multiple, named providers**
|
197
|
+
|
198
|
+
If you want to give your users a choice of authentication methods,
|
199
|
+
configure multiple providers and give them each a unique name. The
|
200
|
+
following example lets users choose between Okta and Microsoft to log in.
|
201
|
+
Always check with your identity provider to understand the structure of
|
202
|
+
their identity tokens because the returned fields may differ. Remember to
|
203
|
+
set ``{tenant}`` and ``{subdomain}`` in ``server_metadata_url`` for
|
204
|
+
Microsoft and Okta, respectively.
|
205
|
+
|
206
|
+
>>> [auth]
|
207
|
+
>>> redirect_uri = "http://localhost:8501/oauth2callback"
|
208
|
+
>>> cookie_secret = "xxx"
|
209
|
+
>>>
|
210
|
+
>>> [auth.microsoft]
|
211
|
+
>>> client_id = "xxx"
|
212
|
+
>>> client_secret = "xxx"
|
213
|
+
>>> server_metadata_url = "https://login.microsoftonline.com/{tenant}/v2.0/.well-known/openid-configuration"
|
214
|
+
>>>
|
215
|
+
>>> [auth.okta]
|
216
|
+
>>> client_id = "xxx"
|
217
|
+
>>> client_secret = "xxx"
|
218
|
+
>>> server_metadata_url = (
|
219
|
+
... "https://{subdomain}.okta.com/.well-known/openid-configuration"
|
220
|
+
... )
|
221
|
+
|
222
|
+
Your app code:
|
223
|
+
|
224
|
+
>>> import streamlit as st
|
225
|
+
>>>
|
226
|
+
>>> if not st.experimental_user.is_logged_in:
|
227
|
+
>>> st.header("Log in:")
|
228
|
+
>>> if st.button("Microsoft"):
|
229
|
+
>>> st.login("microsoft")
|
230
|
+
>>> if st.button("Okta"):
|
231
|
+
>>> st.login("okta")
|
232
|
+
>>> else:
|
233
|
+
>>> if st.button("Log out"):
|
234
|
+
>>> st.logout()
|
235
|
+
>>> st.write(f"Hello, {st.experimental_user.name}!")
|
236
|
+
|
237
|
+
**Example 4: Change the default connection settings**
|
238
|
+
|
239
|
+
``prompt="select_account"`` may be treated differently by some
|
240
|
+
providers when a user is already logged into their account. If a user is
|
241
|
+
logged into their Google or Microsoft account from a previous session, the
|
242
|
+
provider will prompt them to select the account they want to use, even if
|
243
|
+
it's the only one. However, if the user is logged into their Okta or Auth0
|
244
|
+
account from a previous session, the account will automatically be
|
245
|
+
selected. ``st.logout()`` does not clear a user's related cookies. To force
|
246
|
+
users to log in every time, use ``prompt="login"`` as described in Auth0's
|
247
|
+
`Customize Signup and Login Prompts
|
248
|
+
<https://auth0.com/docs/customize/login-pages/universal-login/customize-signup-and-login-prompts>`_.
|
249
|
+
|
250
|
+
``.streamlit/secrets.toml``:
|
251
|
+
|
252
|
+
>>> [auth]
|
253
|
+
>>> redirect_uri = "http://localhost:8501/oauth2callback"
|
254
|
+
>>> cookie_secret = "xxx"
|
255
|
+
>>>
|
256
|
+
>>> [auth.auth0]
|
257
|
+
>>> client_id = "xxx"
|
258
|
+
>>> client_secret = "xxx"
|
259
|
+
>>> server_metadata_url = (
|
260
|
+
... "https://{account}.{region}.auth0.com/.well-known/openid-configuration"
|
261
|
+
... )
|
262
|
+
>>> client_kwargs = { "prompt" = "login" }
|
263
|
+
|
264
|
+
Your app code:
|
265
|
+
|
266
|
+
>>> import streamlit as st
|
267
|
+
>>> if st.button("Log in"):
|
268
|
+
>>> st.login("auth0")
|
269
|
+
>>> if st.experimental_user.is_logged_in:
|
270
|
+
>>> if st.button("Log out"):
|
271
|
+
>>> st.logout()
|
272
|
+
>>> st.write(f"Hello, {st.experimental_user.name}!)
|
273
|
+
|
59
274
|
"""
|
60
275
|
if provider is None:
|
61
276
|
provider = "default"
|
@@ -75,7 +290,47 @@ def login(provider: str | None = None) -> None:
|
|
75
290
|
|
76
291
|
@gather_metrics("logout")
|
77
292
|
def logout() -> None:
|
78
|
-
"""Logout the current user.
|
293
|
+
"""Logout the current user.
|
294
|
+
|
295
|
+
This command removes the user's information from ``st.experimental_user``,
|
296
|
+
deletes their identity cookie, and redirects them back to your app's home
|
297
|
+
page. This creates a new session.
|
298
|
+
|
299
|
+
If the user has multiple sessions open in the same browser,
|
300
|
+
``st.experimental_user`` will not be cleared in any other session.
|
301
|
+
``st.experimental_user`` only reads from the identity cookie at the start
|
302
|
+
of a session. After a session is running, you must call ``st.login()`` or
|
303
|
+
``st.logout()`` within that session to update ``st.experimental_user``.
|
304
|
+
|
305
|
+
.. Note::
|
306
|
+
This does not log the user out of their underlying account from the
|
307
|
+
identity provider.
|
308
|
+
|
309
|
+
Example
|
310
|
+
-------
|
311
|
+
``.streamlit/secrets.toml``:
|
312
|
+
|
313
|
+
>>> [auth]
|
314
|
+
>>> redirect_uri = "http://localhost:8501/oauth2callback"
|
315
|
+
>>> cookie_secret = "xxx"
|
316
|
+
>>> client_id = "xxx"
|
317
|
+
>>> client_secret = "xxx"
|
318
|
+
>>> server_metadata_url = (
|
319
|
+
... "https://accounts.google.com/.well-known/openid-configuration"
|
320
|
+
... )
|
321
|
+
|
322
|
+
Your app code:
|
323
|
+
|
324
|
+
>>> import streamlit as st
|
325
|
+
>>>
|
326
|
+
>>> if not st.experimental_user.is_logged_in:
|
327
|
+
>>> if st.button("Log in"):
|
328
|
+
>>> st.login()
|
329
|
+
>>> else:
|
330
|
+
>>> if st.button("Log out"):
|
331
|
+
>>> st.logout()
|
332
|
+
>>> st.write(f"Hello, {st.experimental_user.name}!")
|
333
|
+
"""
|
79
334
|
context = _get_script_run_ctx()
|
80
335
|
if context is not None:
|
81
336
|
context.user_info.clear()
|
@@ -115,15 +370,113 @@ def _get_user_info() -> UserInfo:
|
|
115
370
|
|
116
371
|
class UserInfoProxy(Mapping[str, Union[str, bool, None]]):
|
117
372
|
"""
|
118
|
-
A read-only, dict-like object for accessing information about current
|
373
|
+
A read-only, dict-like object for accessing information about the current
|
374
|
+
user.
|
119
375
|
|
120
|
-
``st.experimental_user`` is dependent on the host platform running
|
376
|
+
``st.experimental_user`` is dependent on the host platform running your
|
121
377
|
Streamlit app. If the host platform has not configured the function, it
|
122
|
-
will behave as
|
378
|
+
will behave as in a locally running app.
|
379
|
+
|
380
|
+
When authentication is configured in ``secrets.toml``, Streamlit will parse
|
381
|
+
the OpenID Connect (OIDC) identity token and copy the attributes to
|
382
|
+
``st.experimental_user``. Check your provider's documentation for their
|
383
|
+
available attributes (known as claims).
|
123
384
|
|
124
|
-
|
125
|
-
|
385
|
+
When authentication is not configured, ``st.experimental_user`` has no
|
386
|
+
attributes.
|
126
387
|
|
388
|
+
You can access values via key or attribute notation. For example, use
|
389
|
+
``st.experimental_user["email"]`` or ``st.experimental_user.email`` to
|
390
|
+
access the ``email`` attribute.
|
391
|
+
|
392
|
+
.. Important::
|
393
|
+
Identity tokens include an issuance and expiration time. Streamlit does
|
394
|
+
not implicitly check these. If you want to automatically expire a
|
395
|
+
user's authentication, check these values manually and programmatically
|
396
|
+
log out your user (``st.logout()``) when needed.
|
397
|
+
|
398
|
+
Attributes
|
399
|
+
----------
|
400
|
+
is_logged_in: bool
|
401
|
+
Whether a user is logged in. For a locally running app, this attribute
|
402
|
+
is only available when authentication (``st.login()``) is configured in
|
403
|
+
``secrets.toml``. Otherwise, it does not exist.
|
404
|
+
|
405
|
+
Examples
|
406
|
+
--------
|
407
|
+
**Example 1: Google's identity token**
|
408
|
+
|
409
|
+
If you configure a basic Google OIDC connection as shown in Example 1 of
|
410
|
+
``st.login()``, the following data is available in
|
411
|
+
``st.experimental_user``. Streamlit adds the ``is_logged_in`` attribute.
|
412
|
+
Additional attributes may be available depending on the configuration of
|
413
|
+
the user's Google account. For more information about Google's identity
|
414
|
+
tokens, see `Obtain user information from the ID token
|
415
|
+
<https://developers.google.com/identity/openid-connect/openid-connect#obtainuserinfo>`_
|
416
|
+
in Google's docs.
|
417
|
+
|
418
|
+
Your app code:
|
419
|
+
|
420
|
+
>>> import streamlit as st
|
421
|
+
>>>
|
422
|
+
>>> if st.experimental_user.is_logged_in:
|
423
|
+
>>> st.write(st.experimental_user)
|
424
|
+
|
425
|
+
Displayed data when a user is logged in:
|
426
|
+
|
427
|
+
>>> {
|
428
|
+
>>> "is_logged_in":true
|
429
|
+
>>> "iss":"https://accounts.google.com"
|
430
|
+
>>> "azp":"{client_id}.apps.googleusercontent.com"
|
431
|
+
>>> "aud":"{client_id}.apps.googleusercontent.com"
|
432
|
+
>>> "sub":"{unique_user_id}"
|
433
|
+
>>> "email":"{user}@gmail.com"
|
434
|
+
>>> "email_verified":true
|
435
|
+
>>> "at_hash":"{access_token_hash}"
|
436
|
+
>>> "nonce":"{nonce_string}"
|
437
|
+
>>> "name":"{full_name}"
|
438
|
+
>>> "picture":"https://lh3.googleusercontent.com/a/{content_path}"
|
439
|
+
>>> "given_name":"{given_name}"
|
440
|
+
>>> "family_name":"{family_name}"
|
441
|
+
>>> "iat":{issued_time}
|
442
|
+
>>> "exp":{expiration_time}
|
443
|
+
>>> }
|
444
|
+
|
445
|
+
**Example 2: Microsoft's identity token**
|
446
|
+
|
447
|
+
If you configure a basic Microsoft OIDC connection as shown in Example 2 of
|
448
|
+
``st.login()``, the following data is available in
|
449
|
+
``st.experimental_user``. For more information about Microsoft's identity
|
450
|
+
tokens, see `ID token claims reference
|
451
|
+
<https://learn.microsoft.com/en-us/entra/identity-platform/id-token-claims-reference>`_
|
452
|
+
in Microsoft's docs.
|
453
|
+
|
454
|
+
Your app code:
|
455
|
+
|
456
|
+
>>> import streamlit as st
|
457
|
+
>>>
|
458
|
+
>>> if st.experimental_user.is_logged_in:
|
459
|
+
>>> st.write(st.experimental_user)
|
460
|
+
|
461
|
+
Displayed data when a user is logged in:
|
462
|
+
|
463
|
+
>>> {
|
464
|
+
>>> "is_logged_in":true
|
465
|
+
>>> "ver":"2.0"
|
466
|
+
>>> "iss":"https://login.microsoftonline.com/{tenant_id}/v2.0"
|
467
|
+
>>> "sub":"{application_user_id}"
|
468
|
+
>>> "aud":"{application_id}"
|
469
|
+
>>> "exp":{expiration_time}
|
470
|
+
>>> "iat":{issued_time}
|
471
|
+
>>> "nbf":{start_time}
|
472
|
+
>>> "name":"{full_name}"
|
473
|
+
>>> "preferred_username":"{username}"
|
474
|
+
>>> "oid":"{user_GUID}"
|
475
|
+
>>> "email":"{email}"
|
476
|
+
>>> "tid":"{tenant_id}"
|
477
|
+
>>> "nonce":"{nonce_string}"
|
478
|
+
>>> "aio":"{opaque_string}"
|
479
|
+
>>> }
|
127
480
|
"""
|
128
481
|
|
129
482
|
def __getitem__(self, key: str) -> str | bool | None:
|