Tokeny dostępusą używane w uwierzytelnianiu opartym na tokenie, aby umożliwić aplikacji dostęp do interfejsu API. Aplikacja otrzymuje token dostępu po pomyślnym uwierzytelnieniu i autoryzacji dostępu przez użytkownika, a następnie przekazuje token dostępu jako poświadczenie, gdy wywołuje docelowy interfejs API. Przekazany token informuje API, że posiadacz tokena został upoważniony do dostępu do API i wykonywania określonych przez niego czynnościZakresktóre zostało przyznane podczas autoryzacji.
Ponadto, jeśli zdecydowałeś się zezwolić użytkownikom na logowanie się za pomocą plikuDostawca tożsamości (dostawca tożsamości), takich jak Facebook,IdPwystawi własny token dostępu, aby umożliwić Twojej aplikacji wywołanie interfejsu API dostawcy tożsamości. Na przykład, jeśli użytkownik uwierzytelnia się za pomocą Facebooka, token dostępu wystawiony przez Facebooka może zostać użyty do wywołania interfejsu API Facebook Graph. Te tokeny są kontrolowane przez dostawcę tożsamości i mogą być wydawane w dowolnym formacie. WidziećTokeny dostępu dostawcy tożsamościdla szczegółów.
Nieprzezroczyste tokeny dostępu
Nieprzezroczyste tokeny dostępu to tokeny w zastrzeżonym formacie, do których nie masz dostępu i zazwyczaj zawierają pewien identyfikator informacji w trwałym magazynie serwera. Aby sprawdzić poprawność nieprzezroczystego tokena, odbiorca tokenu musi zadzwonić do serwera, który go wystawił.
W przypadku Auth0 nieprzezroczyste tokeny mogą być używane z/Informacje użytkownika
punkt końcowy, aby zwrócić profil użytkownika. Jeśli otrzymasz nieprzezroczysty token dostępu, nie musisz go weryfikować. Możesz go używać z/Informacje użytkownika
punkt końcowy, a Auth0 zajmie się resztą. Aby dowiedzieć się więcej, zobaczZdobądź tokeny dostępu.
Tokeny dostępu JWT
Token internetowy JSON(JWT) tokeny dostępu są zgodne zStandard JWTi zawierają informacje o podmiocie w postaci roszczeń. Są samowystarczalne, dlatego odbiorca nie musi dzwonić do serwera w celu weryfikacji tokena.
Tokeny dostępu wydane dlaInterfejs API zarządzaniaa tokeny dostępu wydawane dla dowolnego niestandardowego API, które zarejestrowałeś w Auth0, są zgodne ze standardem JWT, co oznacza, że ich podstawowa struktura jest zgodna z typowymStruktura JWTi zawierają standardtwierdzi JWTtwierdzono o samym tokenie.
Tokeny dostępu do interfejsu API zarządzania
Token dostępu wystawiony dla interfejsu Auth0 Management API powinien być traktowany jako nieprzezroczysty (niezależnie od tego, czy faktycznie taki jest), więc nie trzeba go weryfikować. Możesz go używać z interfejsem API zarządzania Auth0, a Auth0 zajmie się resztą. Aby dowiedzieć się więcej, zobaczTokeny API zarządzania Auth0.
Niestandardowe tokeny dostępu API
Jeśli weryfikacja niestandardowego tokena dostępu do interfejsu API nie powiedzie się, upewnij się, że został wystawiony z niestandardowym interfejsem API jakopubliczność
. Aby dowiedzieć się więcej, zobaczZdobądź tokeny dostępu.
Przykładowy token dostępu
Ten przykład pokazuje zawartość tokenu dostępu. Zwróć uwagę, że token zawiera tylko informacje autoryzacyjne dotyczące akcji, które aplikacja może wykonywać w interfejsie API (takie uprawnienia są określane jakozakresy
).
{"iss": "https://moja-domena.auth0.com/","sub": "auth0|123456","aud": ["https://example.com/zdrowie-api"," https://my-domain.auth0.com/userinfo"],"azp": "my_client_id","exp": 1311281970,"iat": 1311280970,"scope": "otwarty profil odczyt: pacjenci przeczytali: administrator" }
czy było to pomocne?
/
Token nie zawiera żadnych informacji o użytkowniku poza identyfikatorem użytkownika (znajdującym się w plikupod
prawo). W wielu przypadkach może okazać się przydatne pobranie dodatkowych informacji o użytkowniku. Możesz to zrobić dzwoniąc pod nrpunkt końcowy interfejsu API informacji o użytkownikuz tokenem dostępu. Upewnij się, że interfejs API, dla którego wystawiono token dostępu, korzysta zRS256 algorytm podpisywania.
Uzyskaj dostęp do bezpieczeństwa tokena
Powinieneś podążaćnajlepsze praktyki tokenówpodczas korzystania z tokenów dostępu i JWT upewnij się, że tyzweryfikować token dostępuprzed założeniem, że można ufać jego zawartości.
Czas życia tokena dostępu
Niestandardowy czas życia tokena interfejsu API
Domyślnie token dostępu dla niestandardowego interfejsu API jest ważny przez 86400 sekund (24 godziny). Zalecamy ustawienie okresu ważności tokena na podstawie wymagań bezpieczeństwa Twojego interfejsu API. Na przykład token dostępu, który uzyskuje dostęp do bankowego interfejsu API, powinien wygasać szybciej niż token, który uzyskuje dostęp do interfejsu API zadań. Aby dowiedzieć się więcej, zobaczZaktualizuj czas życia tokena dostępu.
/userinfo czas życia tokena punktu końcowego
Tokeny dostępu wydawane wyłącznie w celu uzyskania dostępu do OIDC/Informacje użytkownika
punkt końcowy ma domyślny czas życia i nie można go zmienić. Długość życia zależy od przepływu użytego do uzyskania tokena:
Przepływ | Dożywotni |
---|---|
Domniemany | 7200 sekund (2 godziny) |
Kod autoryzacyjny/hybrydowy | 86400 sekund (24 godziny) |