Auth Module🔗
The earthdaily.earthone.auth module handles authentication against the EarthOne platform, including JWT token management, OAuth integration, and credential resolution from multiple sources (parameters, environment variables, cached tokens).
Auth🔗
Auth 🔗
Client used to authenticate with all EarthOne service APIs.
Source code in earthdaily/earthone/auth/auth.py
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 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 | |
token
property
🔗
payload
property
🔗
Gets the token payload.
Returns🔗
dict Dictionary containing the fields specified by scope, which may include:
.. highlight:: none
::
name: The name of the user.
groups: Groups to which the user belongs.
org: The organization to which the user belongs.
email: The email address of the user.
email_verified: True if the user's email has been verified.
sub: The user identifier.
exp: The expiration time of the token, in seconds since
the start of the unix epoch.
Raises🔗
AuthError Raised when incomplete credentials were provided. OauthError Raised when a token cannot be obtained or refreshed.
namespace
property
🔗
all_acl_subjects
property
🔗
A list of all ACL subjects identifying this user (the user itself, the org, the groups) which can be used in ACL queries.
all_owner_acl_subjects
property
🔗
A list of ACL subjects identifying this user (the user itself, the org, org admin and catalog admins) which can be used in owner ACL queries.
__init__ 🔗
__init__(domain=None, scope=None, leeway=500, token_info_path=_default_token_info_path, client_id=None, client_secret=None, jwt_token=None, refresh_token=None, retries=None, _suppress_warning=False)
Retrieves a JWT access token from a client id and refresh token for cli usage.
By default and without arguments the credentials are retrieved from a
config file named token_info.json. This file can be created by running
earthone auth login from the command line.
You can change the default location by setting the environment variable
EARTHONE_TOKEN_INFO_PATH. Make sure you do this before running
earthone auth login so the credentials will be saved to the file
specified in the environment variable, and when still set when instantiating
this class, the credentials will be read from that file.
To use a short-lived access token that will not be refreshed, either set the
environment variable EARTHONE_TOKEN or use the jwt_token parameter.
To use a long-lived refresh token that will be refreshed, either set the
environment variables EARTHONE_CLIENT_ID and
EARTHONE_CLIENT_SECRET or use the parameters client_id and
client_secret. This will retrieve an access token which will be cached
between instances for the same combination of client id and client secret.
If in addition to the client id and client secret you also specify a valid short-lived access token, it will be used until it expires.
Note that the environment variable EARTHONE_REFRESH_TOKEN is identical
to EARTHONE_CLIENT_SECRET and the parameter refresh_token is
identical to client_secret. Use one or the other but not both.
Although discouraged, it is possible to set one value as environment variable,
and pass the other value in as parameter. For example, one could set the
environment variable EARTHONE_CLIENT_ID and only pass in the parameter
client_secret.
If you also specify a token_info_path that indicates which file to
read the credentials from. If used by itself, it works the same as
EARTHONE_TOKEN_INFO_PATH and assuming the file exists and contains
valid credentials, you could switch between accounts this way.
If you specify the token_info_path together with an additional
client id and client secret (whether retrieved through environment
variables or given using parameters), the given credentials will be
written to the given file. If this file already exists and contains
matching credentials, it will be used to retrieve the short-lived
access token and refreshes it when it expires. If the file already
exists and contains conflicting credentials, it will be overwritten
with the new credentials.
Parameters🔗
str, default earthdaily.earthone.config.get_settings().IAM_URL
The domain used for the credentials. You should normally never change this.
scope : list(str), optional
The JWT access token fields to be included. You should normally
never have to use this.
leeway : int, default 500
The leeway is given in seconds and is used as a safety cushion
for the expiration. If the expiration falls within the leeway,
the JWT access token will be renewed.
token_info_path : str, default ~/.earthone/token_info.json
Path to a JSON file holding the credentials. If not set and
credentials are provided through environment variables or through
parameters, this parameter will not be used. However, if no
credentials are provided through environment variables or through
parameters, it will default to ~/.earthone/token_info.json
and credentials will be retrieved from that file if present. If
explicitly set to None, credentials will never be retrieved
from file and must be provided through environment variables
or parameters.
client_id : str, optional
The JWT client id. If provided it will take precedence over the
corresponding environment variable, or the credentials retrieved through
the file specified in token_info_path. If this parameter is provided,
you must either provide a client_secret or refresh_token (but not
both). Access tokens retrieved this way will be cached without revealing
the client secret.
client_secret : str, optional
The refresh token used to retrieve short-lived access tokens. If provided
it will take precedence over the corresponding environment variable, or the
credentials retrieved through the file specified in token_info_path. If
this parameter is provided, you must also provide a client id either as
a parameter or through an environment variable. Access tokens retrieved this
way will be cached without revealing the client secret.
jwt_token : str, optional
A short-lived JWT access token. If valid and used without other parameters,
it will be used for access. If used with a client id, the access token must
match or it will be discarded. If the access token is discarded either
because it expired or didn't match the given client id, and no client secret
has been given, no new access token can be retrieved and access will be
denied. If used with both client id and client secret, the token will be
cached and updated as needed without revealing the client secret.
refresh_token : str, optional
Identical to the client_secret. You can only specify one or the other,
or if specified both, they must match. The refresh token takes precedence
over the client secret.
retries : Retry or int, optional
The number of retries and backoff policy;
by default 5 retries with a random backoff policy between 1 and 10 seconds.
Raises🔗
UserWarning
In case the refresh token and client secret differ.
In case the defailt or given token_info_path cannot be found.
In case no credentials can be found.
Examples🔗
from earthdaily.earthone.auth import Auth
Use default credentials obtained through 'earthone auth login'🔗
auth = Auth()
Your EarthOne user id🔗
auth.namespace # doctest: +SKIP 'a54d88e06612d820bc3be72877c74f257b561b19' auth = Auth( ... client_id="some-client-id", ... client_secret="some-client-secret", ... ) auth.namespace # doctest: +SKIP '67f21eb1040f978fe1da32e5e33501d0f4a604ac'
Source code in earthdaily/earthone/auth/auth.py
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 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | |
from_environment_or_token_json
classmethod
🔗
Creates an Auth object from the given arguments.
Creates an Auth object from the given arguments, environment variables, or stored credentials.
See class:
Auth for details.
Source code in earthdaily/earthone/auth/auth.py
get_default_auth
staticmethod
🔗
Retrieve the default Auth.
This Auth is used whenever you don't explicitly set the Auth when creating clients, etc.
Source code in earthdaily/earthone/auth/auth.py
set_default_auth
staticmethod
🔗
Change the default Auth to the given Auth.
This is the Auth that will be used whenever you don't explicitly set the Auth when creating clients, etc.