Spaces:
Sleeping
Sleeping
File size: 10,025 Bytes
036b3a6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 |
# OAuth
<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->
See the [docs page](https://www.fastht.ml/docs/explains/oauth.html) for
an explanation of how to use this.
``` python
from IPython.display import Markdown
```
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L23"
target="_blank" style="float:right; font-size:smaller">source</a>
### GoogleAppClient
> GoogleAppClient (client_id, client_secret, code=None, scope=None,
> project_id=None, **kwargs)
*A `WebApplicationClient` for Google oauth2*
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L42"
target="_blank" style="float:right; font-size:smaller">source</a>
### GitHubAppClient
> GitHubAppClient (client_id, client_secret, code=None, scope=None,
> **kwargs)
*A `WebApplicationClient` for GitHub oauth2*
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L54"
target="_blank" style="float:right; font-size:smaller">source</a>
### HuggingFaceClient
> HuggingFaceClient (client_id, client_secret, code=None, scope=None,
> state=None, **kwargs)
*A `WebApplicationClient` for HuggingFace oauth2*
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L67"
target="_blank" style="float:right; font-size:smaller">source</a>
### DiscordAppClient
> DiscordAppClient (client_id, client_secret, is_user=False, perms=0,
> scope=None, **kwargs)
*A `WebApplicationClient` for Discord oauth2*
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L98"
target="_blank" style="float:right; font-size:smaller">source</a>
### Auth0AppClient
> Auth0AppClient (domain, client_id, client_secret, code=None, scope=None,
> redirect_uri='', **kwargs)
*A `WebApplicationClient` for Auth0 OAuth2*
``` python
# cli = GoogleAppClient.from_file('client_secret.json')
```
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L117"
target="_blank" style="float:right; font-size:smaller">source</a>
### WebApplicationClient.login_link
> WebApplicationClient.login_link (redirect_uri, scope=None, state=None,
> **kwargs)
*Get a login link for this client*
Generating a login link that sends the user to the OAuth provider is
done with `client.login_link()`.
It can sometimes be useful to pass state to the OAuth provider, so that
when the user returns you can pick up where they left off. This can be
done by passing the `state` parameter.
``` python
from fasthtml.jupyter import *
```
``` python
redir_path = '/redirect'
port = 8000
```
``` python
app,rt = fast_app()
server = JupyUvi(app, port=port)
```
<script>
document.body.addEventListener('htmx:configRequest', (event) => {
if(event.detail.path.includes('://')) return;
htmx.config.selfRequestsOnly=false;
event.detail.path = `${location.protocol}//${location.hostname}:8000${event.detail.path}`;
});
</script>
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L124"
target="_blank" style="float:right; font-size:smaller">source</a>
### redir_url
> redir_url (request, redir_path, scheme=None)
*Get the redir url for the host in `request`*
``` python
@rt
def index(request):
redir = redir_url(request, redir_path)
return A('login', href=cli.login_link(redir), target='_blank')
```
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L131"
target="_blank" style="float:right; font-size:smaller">source</a>
### \_AppClient.parse_response
> _AppClient.parse_response (code, redirect_uri)
*Get the token from the oauth2 server response*
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L141"
target="_blank" style="float:right; font-size:smaller">source</a>
### \_AppClient.get_info
> _AppClient.get_info (token=None)
*Get the info for authenticated user*
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L149"
target="_blank" style="float:right; font-size:smaller">source</a>
### \_AppClient.retr_info
> _AppClient.retr_info (code, redirect_uri)
*Combines `parse_response` and `get_info`*
``` python
@rt(redir_path)
def get(request, code:str):
redir = redir_url(request, redir_path)
info = cli.retr_info(code, redir)
return P(f'Login successful for {info["name"]}!')
```
``` python
# HTMX()
```
``` python
server.stop()
```
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L156"
target="_blank" style="float:right; font-size:smaller">source</a>
### \_AppClient.retr_id
> _AppClient.retr_id (code, redirect_uri)
*Call `retr_info` and then return id/subscriber value*
After logging in via the provider, the user will be redirected back to
the supplied redirect URL. The request to this URL will contain a `code`
parameter, which is used to get an access token and fetch the user’s
profile information. See [the explanation
here](https://www.fastht.ml/docs/explains/oauth.html) for a worked
example. You can either:
- Use client.retr_info(code) to get all the profile information, or
- Use client.retr_id(code) to get just the user’s ID.
After either of these calls, you can also access the access token (used
to revoke access, for example) with `client.token["access_token"]`.
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L162"
target="_blank" style="float:right; font-size:smaller">source</a>
### url_match
> url_match (url, patterns=('^(localhost|127\\.0\\.0\\.1)(:\\d+)?$',))
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L166"
target="_blank" style="float:right; font-size:smaller">source</a>
### OAuth
> OAuth (app, cli, skip=None, redir_path='/redirect', error_path='/error',
> logout_path='/logout', login_path='/login', https=True,
> http_patterns=('^(localhost|127\\.0\\.0\\.1)(:\\d+)?$',))
*Initialize self. See help(type(self)) for accurate signature.*
### Google helpers
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L216"
target="_blank" style="float:right; font-size:smaller">source</a>
### GoogleAppClient.consent_url
> GoogleAppClient.consent_url (proj=None)
*Get Google OAuth consent screen URL*
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L216"
target="_blank" style="float:right; font-size:smaller">source</a>
### GoogleAppClient.consent_url
> GoogleAppClient.consent_url (proj=None)
*Get Google OAuth consent screen URL*
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L224"
target="_blank" style="float:right; font-size:smaller">source</a>
### Credentials.update
> Credentials.update ()
*Refresh the credentials if they are expired, and return them*
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L224"
target="_blank" style="float:right; font-size:smaller">source</a>
### Credentials.update
> Credentials.update ()
*Refresh the credentials if they are expired, and return them*
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L231"
target="_blank" style="float:right; font-size:smaller">source</a>
### Credentials.save
> Credentials.save (fname)
*Save credentials to `fname`*
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L231"
target="_blank" style="float:right; font-size:smaller">source</a>
### Credentials.save
> Credentials.save (fname)
*Save credentials to `fname`*
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L236"
target="_blank" style="float:right; font-size:smaller">source</a>
### load_creds
> load_creds (fname)
*Load credentials from `fname`*
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L242"
target="_blank" style="float:right; font-size:smaller">source</a>
### GoogleAppClient.creds
> GoogleAppClient.creds ()
*Create `Credentials` from the client, refreshing if needed*
------------------------------------------------------------------------
<a
href="https://github.com/AnswerDotAI/fasthtml/blob/main/fasthtml/oauth.py#L242"
target="_blank" style="float:right; font-size:smaller">source</a>
### GoogleAppClient.creds
> GoogleAppClient.creds ()
*Create `Credentials` from the client, refreshing if needed*
|