angel3_auth_server 10.1.0
angel3_auth_server: ^10.1.0 copied to clipboard
A class containing handlers that can be used within Angel3 to build a spec-compliant OAuth 2.0 server.
Change Log #
10.1.0 #
New in 10.1.0 #
- Mutual TLS: Clients may authenticate by a TLS client certificate (RFC 8705 §2).
verifyClientCertificatedecides whether the certificate of a request that gives aclient_idand no secret is the client's; a client that it accepts is confidential, so it may use the client credentials grant and introspect tokens.clientCertificateOfgives the certificate of a request, by default of its TLS connection, and may be overridden to read one that a reverse proxy forwards, withClientCertificate.fromPem. Requiresangel3_framework10.2.0 - Certificate-bound access tokens:
AccessToken.certificateThumbprintbinds a token to a client certificate (RFC 8705 §3):requireTokenrefuses it,invalid_token, of a request that does not present that certificate, and introspection gives it as thex5t#S256ofcnf.ClientCertificate.thumbprintis the thumbprint to store - Metadata:
ServerMetadatatakestlsClientCertificateBoundAccessTokensandmtlsEndpointAliases, given astls_client_certificate_bound_access_tokensandmtls_endpoint_aliases - Registration: A client of
tls_client_authmust register exactly one of thetls_client_auth_subject_dnandtls_client_auth_san_*metadata, and one ofself_signed_tls_client_authitsjwksorjwks_uri; neither is issued a secret.tls_client_certificate_bound_access_tokensmust be a boolean, and may betrueonly of a server that binds tokens
Fixes in 10.1.0 #
- Registration: A
jwksthat is not a JSON object isinvalid_client_metadata, where it was registered as it was - Docs: The README is rewritten with a Client Authentication section, subsections for the implicit grant, extension grants and registration metadata checks, and lists and tables in place of long paragraphs. A Mutual TLS section covers certificate authentication, bound tokens, and reverse proxies, with nginx and Apache httpd configurations that forward the client certificate, and accept self-signed ones. Its installation snippet asks for
angel3_framework10.2.0, which the package requires
10.0.0 #
Breaking changes in 10.0.0 #
- Breaking: Renamed from
angel3_oauth2: depend onangel3_auth_server, and importpackage:angel3_auth_server/angel3_auth_server.dart - Breaking: A client that cannot be authenticated at the token endpoint, of no credentials, a malformed
Authorization: Basicheader, an unknown id or a wrong secret, isinvalid_client, a 401, as RFC 6749 requires, where it wasunauthorized_client, a 400; withWWW-Authenticate: Basic realm="oauth2", as every 401 has (RFC 7235 §3.1), of credentials of the header or of the form alike. So is an unknownclient_idof a device code request or grant - Breaking: A grant type that the server does not support, unknown or not implemented, is
unsupported_grant_type, where it wasinvalid_requestorunsupported_response_type. An unknown grant type is refused before the client is authenticated; a known one that the server does not implement is refused once the request is well-formed, so one without itscode,code_verifierorusernameis stillinvalid_request - Breaking: A device code request is no longer taken at the token endpoint, without a
grant_type: route adeviceAuthorizationEndpoint(RFC 8628 §3.1), and point device clients at it. A request to the token endpoint without agrant_type, or with an emptygrant_type=, isinvalid_request, before the client is authenticated. WithoutrequestDeviceCode, a device authorization request isunsupported_grant_type, where it wasinvalid_request - Breaking: An empty client secret, of
Basic id:orclient_secret=, is given toverifyClientasnull, as no secret is, where it was'': averifyClientthat compares it with a stored''must acceptnull - Breaking: A device code request or grant authenticates its client as the other grants do, where its
client_idwas only looked up, and its secret ignored: a confidential client must give its secret, by anAuthorization: Basicheader, with or without aclient_id, or byclient_secret, or it isinvalid_client. A public client gives itsclient_idalone, andverifyClientis given anullsecret, for which it must returntruefor that client. A request without aclient_idor a header isinvalid_client, where it wasinvalid_request - Breaking: A
client_idorclient_secretin the form of a request with anAuthorization: Basicheader must be that of the header, or it isinvalid_request, where it was ignored; once the header's credentials are verified, so that wrong ones are stillinvalid_client - Breaking: The
scopeof a token response is a string of space-separated scopes, as RFC 6749 requires, where it was a JSON list, which clients such aspackage:oauth2refused - Breaking: The token request of an authorization code grant may leave out its
redirect_uri(RFC 6749 §4.1.3):exchangeAuthorizationCodeForTokenis givennull, and must check it against the one stored with the code, which the token request must then give - Breaking: At the authorization endpoint, the client is found before the
response_typeis read, and an unknownresponse_typeisunsupported_response_type, where it wasinvalid_request; a missing one is stillinvalid_request. An unknownclient_idisinvalid_request, where it was a 500 - Breaking:
clientCredentialsGrantis given thescopesof the request (RFC 6749 §4.4.2), as the password and refresh token grants are: addIterable<String> scopesafter itsclientparameter - Breaking: An authorization code grant must use PKCE with
S256(RFC 7636), as OAuth 2.1 and RFC 9700 have it: its authorization request must give acode_challengeandcode_challenge_method=S256, where none, orplain, was accepted, and its token request acode_verifier, of 43 to 128 characters, and the challenge of 43, the base64url of a SHA-256 hash, or it isinvalid_request. OverriderequiresPkceto returnfalsefor clients that cannot use PKCE, andallowsPlainPkceto returntrueto acceptplain.exchangeAuthorizationCodeForTokenmust still compare the verifier with the stored challenge, byPkce.validate - Breaking: The implicit grant, of
response_type=token, is refused by default, asunsupported_response_type, as OAuth 2.1 and RFC 9700 have it, where every request was given torequestAuthorizationCode. Override the newallowsImplicitGrantto returntruefor clients that still use it - Breaking: The token endpoint no longer injects a
Pkceinto the request's container: one of the token request, which has acode_verifierand no challenge, failed for honest clients, and passed for one that sent acode_challengeof its own with its verifier. Build thePkceof the challenge stored with the code, as the README shows - Breaking: The client id and secret of the
Authorization: Basicheader are percent-decoded, as clients encode them (RFC 6749 §2.3.1): a secret of a valid%XX, such asa%20b, sent unencoded, as 9.x matched it, is nowa b, and refused. Encode such a secret, aspackage:oauth2does; a%that is not of a valid%XXis still kept
New in 10.0.0 #
-
Client authentication: Without an
Authorizationheader, a client is authenticated by theclient_idandclient_secretof the form of its request to the token endpoint (RFC 6749 §2.3.1); a public client, as of PKCE, gives itsclient_idalone, andverifyClientis given anullsecret. A client authenticated without a secret may not use the client credentials grant, which is for confidential clients (RFC 6749 §4.4): it isunauthorized_client, a 400 -
Redirect URIs:
registeredRedirectUrichecks theredirect_uriof an authorization request against those registered for the client. Once it returns one, the request may leave out itsredirect_uri, and its errors are redirected to it, with theirerror,error_descriptionandstate, after its query, which is kept as it is (RFC 6749 §3.1.2), or in the fragment of an implicit grant (RFC 6749 §4.1.2.1, §4.2.2.1). By default, it returnsnull, and the endpoint behaves as before. An unexpected error, of noAuthorizationException, is redirected asserver_error, and logged -
Authorization endpoint: It reads its parameters from the form of a POST, as from the query of a GET (RFC 6749 §3.1); route both to it.
completeAuthorizationCodegives the redirect URI of an authorization code, with itscodeandstateafter its query, which is kept as it is, ascompleteImplicitGrantdoes of a token -
Device authorization:
deviceAuthorizationEndpointhandles device authorization requests at an endpoint of their own, as RFC 8628 §3.1 has them, which standard device clients use: route a POST to it. It authenticates the client as the token endpoint does, and gives theDeviceCodeResponseofrequestDeviceCode, withCache-Control: no-store, or, withoutrequestDeviceCode,unsupported_grant_type -
Protecting resources:
requireTokenprotects the handlers after it with the access tokens of the server (RFC 6750): it reads theAuthorization: Bearerheader, or, if allowed, theaccess_tokenof a form, finds the token byfindAccessToken, which gives anAccessTokenof its client, user, scopes and expiry, and refuses a request without a token, or of an unknown, expired or malformed one, or of one without the scopes required, with theWWW-Authenticate: Bearerchallenge and error of RFC 6750 §3 (invalid_token,insufficient_scope,invalid_request). The handlers after it get theAccessTokenfromreq.container.ErrorResponseaddsinvalidTokenandinsufficientScope -
Token revocation:
revocationEndpointrevokes a token of a client, as when its user logs out (RFC 7009): it authenticates the client as the token endpoint does, gives thetokenand itstoken_type_hinttorevokeToken, and answers a 200 without a body, whether the token was revoked or not; withoutrevokeToken, it isunsupported_token_type, whichErrorResponseadds asunsupportedTokenType -
Server metadata:
metadataEndpointserves the metadata of the server (RFC 8414), from which clients find its endpoints:ServerMetadatagives its issuer, the URLs of its endpoints and the grants it implements, and the server adds its device code and extension grants,implicitof thetokenresponse type, and its PKCE methods;wellKnownPathis the path to route it at, andmetadataOfgives it as aMap -
Token introspection:
introspectionEndpointtells a resource server whether a token is active, and of what (RFC 7662): its caller must authenticate as a client with a secret, whichmayIntrospectallows, as no client is by default; it finds the token byintrospectToken, which isfindAccessTokenby default, and answers{"active": false}for one that is unknown, revoked or expired, or else itsscope,expandiat, and whatintrospectionClaimsgives the caller, which may also make it inactive to it.AccessTokenaddsissuedAt, andServerMetadataanintrospectionEndpoint -
Client registration:
registrationEndpointlets a client register itself (RFC 7591), ifmayRegisterClientaccepts its initial access token: it checks its metadata against theServerMetadataof the server, as its grant, response types, client authentication methods, scopes and redirect URIs; a client of thetokenresponse type alone registers theimplicitgrant type by default; the redirect URIs must behttps,httpof loopback, or of a reverse domain name scheme of a native app, such ascom.example.app:(RFC 8252 §7.1), issues it an id, and a secret unless it is public, and gives theClientRegistrationtoregisterClientto store, and answers a 201 of it, orinvalid_client_metadataorinvalid_redirect_uri, whichErrorResponseadds.registerClientmay change other metadata, such as aclient_name; the response gives the checked metadata, such asgrant_types, of the fields of theClientRegistration, which are what is stored.ServerMetadataadds aregistrationEndpoint, andClientRegistrationacopyWith -
Registration management: If
managesClientRegistrations, a client that registers itself is also issued aregistration_access_tokenand itsregistration_client_uri, at whichregistrationManagementEndpointlets it read, update and delete its registration (RFC 7592): it finds the registration byfindRegistration, of the token, which isinvalid_tokenfor a client that does not exist too; a PUT replaces all its metadata, as a registration is checked, of itsclient_idand itsclient_secret, if given, and is stored byupdateClient, which may be given a new secret and token, ofrotatesClientSecretOnUpdateandrotatesRegistrationAccessToken; a GET and a PUT give the token (RFC 7592 §3); a DELETE is given todeleteClient, a 204.updateClientanddeleteClientrefuse by default. An emptyclient_secretof a PUT is none, as at the token endpoint -
Client metadata:
checkClientMetadatais given the metadata of a registration, or of an update, before the server checks it: to refuse metadata of its own, as of OpenID Connect, or to add defaults. On an update it is also given thecurrentregistration, so a change can be refused -
Server metadata:
ServerMetadata.copyWith, in which anullkeeps the current value -
Authorization requests:
checkAuthorizationRequestis given each authorization request's parameters, beforerequestAuthorizationCode, to check those the server does not know, as of OpenID Connect; its errors are redirected as the endpoint's others -
Redirect URIs:
redirectUriProblemgives why a URI may not be a redirect URI, by the rules of registration, andloopbackHostsis exported
Fixes in 10.0.0 #
-
Repeated parameters: a request whose query or form gives a parameter more than once is
invalid_request, instead of using the last value (RFC 6749 §3.1), at the authorization endpoint, where it is never redirected, and at the token, device authorization, revocation and introspection endpoints.requireTokenwithallowFormParameterrefuses only a repeatedaccess_token, as the rest of the form is the app's own. Forms are checked throughRequestContext.bodyFieldsAll, soangel3_framework10.1.0 is required -
Implicit grant:
completeImplicitGrantgives nostateof a request without one, where it gave an emptystate=(RFC 6749 §4.2.2), and form-encodes its fragment, as its error redirects are, a space as+(RFC 6749 Appendix B) -
PKCE verifier:
getPkceCodeVerifierthrowsinvalid_requestof an emptycode_verifier=, as of a missing one, where it gave'' -
Client credentials: A refresh token is left out of the JSON of the response, where the response was rebuilt without it, and lost what a subclass of
AuthorizationTokenResponseadds -
Token responses: The responses of the token endpoint have
Cache-Control: no-storeandPragma: no-cache, as RFC 6749 §5.1 requires, so that tokens are not cached -
Request bodies: A body that cannot be read, as of malformed JSON or a truncated form, is
invalid_request, a 400, at the token, device, revocation and introspection endpoints, and of a POST to the authorization endpoint, where malformed JSON was a 500server_error, and a malformed form an error of the framework's own form -
Extension grants: One of
extensionGrantsthat names a grant type the server implements itself, such aspassword, which is never called, is warned about once: override the grant's method instead -
Scopes: The password and refresh token grants read
scopefrom the form of the request, where they read the query and got none. Scopes are separated by any spaces, and empty ones are dropped -
Authorization code: The default
exchangeAuthorizationCodeForTokenreadsstatefrom the form, as the other grants do -
PKCE:
code_challenge_method=S256, as RFC 7636 spells it, is accepted, and an S256 challenge is compared without its=padding, so standard clients are no longer refused withinvalid_grant;s256and padded challenges still work. The challenge is compared in constant time. Acode_verifierof non-ASCII characters is compared with the challenge, as UTF-8, where it was a 500 -
Client authentication: The
Basicheader is decoded as UTF-8, where non-ASCII credentials were garbled, and a malformed one, or one of an empty client id, isinvalid_clientinstead of a 500. A client secret may have a$, which cut it short. Only anAuthorizationheader of theBasicscheme is read, of any case, with leading spaces or not, and its base64 may be unpadded; one of another scheme, as of a proxy, is ignored, beside a Basic one or alone, where several headers were a 500, and the client is authenticated by the form; so are headers joined by commas in one value, asHttpClientand the shelf driver join them. Two Basic headers areinvalid_request. A secret of a space or a non-ASCII character, which clients percent-encode, is accepted, where it was refused; a+is kept, aspackage:oauth2does not encode it, and so are escapes that are not valid UTF-8, such as%FF, where they were a 500. An unknown client and a wrong secret are refused with oneerror_description, so that a guess of a secret does not confirm the client id; ids are not secret (RFC 6749 §2.2), and the authorization endpoint names an unknown one -
Example:
example1.dartstarts a server, without importing fromtest/, and answers an error of its status code, where it was a 200 -
Dependencies: Removed the unused
angel3_containerandangel3_validate, and movedcollection, which only the tests use, todev_dependencies -
Tests: The tests and example no longer use
MirrorsReflector;AuthorizationServerneeds no reflection
9.1.0 #
- Require Dart >= 3.13
9.0.0 #
- Require Dart >= 3.12
8.4.0 #
- Require Dart >= 3.8
- Updated
lintsto 6.0.0 - Updated dependencies to the latest release
8.3.0 #
- Require Dart >= 3.6
- Updated
lintsto 5.0.0 - Updated dependencies to the latest release
8.2.0 #
- Require Dart >= 3.3
- Updated
lintsto 4.0.0
8.1.1 #
- Updated repository link
8.1.0 #
- Updated
lintsto 3.0.0 - Fixed linter warnings
8.0.0 #
- Require Dart >= 3.0
- Updated to
uuid
7.0.0 #
- Require Dart >= 2.17
6.0.1 #
- Fixed AngelHttpException error
- [Breaking] Renamed
errortoauthErrorforAuthorizationException
6.0.0 #
- Require Dart >= 2.16
5.0.0 #
- Skipped release
4.1.1 #
- Updated README
4.1.0 #
- Updated linter to
package:lints
4.0.0 #
- Migrated to support Dart >= 2.12 NNBD
3.0.0 #
- Migrated to work with Dart >= 2.12 Non NNBD
2.3.0 #
- Remove
implicitGrant, and inline it intorequestAuthorizationCode.
2.2.0+1 #
- Parse+verify client for
authorization_code.
2.2.0 #
- Pass
clienttoexchangeAuthorizationCodeForToken. - Apply
package:pedantic.
2.0.0 #
- Angel 2 support.
1.0.0+1 #
- Dart2 updates + backwards compatibility assurance.