Skip to content

Commit

Permalink
Merge branch 'master' into api/jwt-auth
Browse files Browse the repository at this point in the history
  • Loading branch information
BeryJu committed Mar 31, 2022
2 parents fbfad16 + 83c4d53 commit 11132c0
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 19 deletions.
2 changes: 2 additions & 0 deletions authentik/providers/oauth2/constants.py
@@ -1,8 +1,10 @@
"""OAuth/OpenID Constants"""

GRANT_TYPE_AUTHORIZATION_CODE = "authorization_code"
GRANT_TYPE_IMPLICIT = "implicit"
GRANT_TYPE_REFRESH_TOKEN = "refresh_token" # nosec
GRANT_TYPE_CLIENT_CREDENTIALS = "client_credentials"
GRANT_TYPE_PASSWORD = "password" # nosec

CLIENT_ASSERTION_TYPE = "client_assertion_type"
CLIENT_ASSERTION = "client_assertion"
Expand Down
@@ -0,0 +1,26 @@
# Generated by Django 4.0.3 on 2022-03-31 18:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("authentik_crypto", "0003_certificatekeypair_managed"),
("authentik_providers_oauth2", "0009_oauth2provider_verification_keys_and_more"),
]

operations = [
migrations.AlterField(
model_name="oauth2provider",
name="verification_keys",
field=models.ManyToManyField(
blank=True,
default=None,
help_text="JWTs created with the configured certificates can authenticate with this provider.",
related_name="+",
to="authentik_crypto.certificatekeypair",
verbose_name="Allowed certificates for JWT-based client_credentials",
),
),
]
2 changes: 2 additions & 0 deletions authentik/providers/oauth2/models.py
Expand Up @@ -227,6 +227,8 @@ class OAuth2Provider(Provider):
"JWTs created with the configured certificates can authenticate with this provider."
),
related_name="+",
default=None,
blank=True,
)

def create_refresh_token(
Expand Down
12 changes: 5 additions & 7 deletions authentik/providers/oauth2/views/provider.py
Expand Up @@ -11,15 +11,12 @@
ACR_AUTHENTIK_DEFAULT,
GRANT_TYPE_AUTHORIZATION_CODE,
GRANT_TYPE_CLIENT_CREDENTIALS,
GRANT_TYPE_IMPLICIT,
GRANT_TYPE_PASSWORD,
GRANT_TYPE_REFRESH_TOKEN,
SCOPE_OPENID,
)
from authentik.providers.oauth2.models import (
GrantTypes,
OAuth2Provider,
ResponseTypes,
ScopeMapping,
)
from authentik.providers.oauth2.models import OAuth2Provider, ResponseTypes, ScopeMapping
from authentik.providers.oauth2.utils import cors_allow

LOGGER = get_logger()
Expand Down Expand Up @@ -78,8 +75,9 @@ def get_info(self, provider: OAuth2Provider) -> dict[str, Any]:
"grant_types_supported": [
GRANT_TYPE_AUTHORIZATION_CODE,
GRANT_TYPE_REFRESH_TOKEN,
GrantTypes.IMPLICIT,
GRANT_TYPE_IMPLICIT,
GRANT_TYPE_CLIENT_CREDENTIALS,
GRANT_TYPE_PASSWORD,
],
"id_token_signing_alg_values_supported": [supported_alg],
# See: http://openid.net/specs/openid-connect-core-1_0.html#SubjectIDTypes
Expand Down
3 changes: 2 additions & 1 deletion authentik/providers/oauth2/views/token.py
Expand Up @@ -28,6 +28,7 @@
CLIENT_ASSERTION_TYPE_JWT,
GRANT_TYPE_AUTHORIZATION_CODE,
GRANT_TYPE_CLIENT_CREDENTIALS,
GRANT_TYPE_PASSWORD,
GRANT_TYPE_REFRESH_TOKEN,
)
from authentik.providers.oauth2.errors import TokenError, UserAuthError
Expand Down Expand Up @@ -108,7 +109,7 @@ def __post_init__(self, raw_code: str, raw_token: str, request: HttpRequest):
self.__post_init_code(raw_code)
elif self.grant_type == GRANT_TYPE_REFRESH_TOKEN:
self.__post_init_refresh(raw_token, request)
elif self.grant_type == GRANT_TYPE_CLIENT_CREDENTIALS:
elif self.grant_type in [GRANT_TYPE_CLIENT_CREDENTIALS, GRANT_TYPE_PASSWORD]:
self.__post_init_client_credentials(request)
else:
LOGGER.warning("Invalid grant type", grant_type=self.grant_type)
Expand Down
3 changes: 2 additions & 1 deletion lifecycle/wait_for_db.py
Expand Up @@ -5,6 +5,7 @@
from sys import exit as sysexit
from sys import stderr
from time import sleep, time
from urllib.parse import quote_plus

from psycopg2 import OperationalError, connect
from redis import Redis
Expand Down Expand Up @@ -58,7 +59,7 @@ def j_print(event: str, log_level: str = "info", **kwargs):
REDIS_PROTOCOL_PREFIX = "rediss://"
REDIS_URL = (
f"{REDIS_PROTOCOL_PREFIX}:"
f"{CONFIG.y('redis.password')}@{CONFIG.y('redis.host')}:"
f"{quote_plus(CONFIG.y('redis.password'))}@{quote_plus(CONFIG.y('redis.host'))}:"
f"{int(CONFIG.y('redis.port'))}/{CONFIG.y('redis.ws_db')}"
)
while True:
Expand Down
2 changes: 0 additions & 2 deletions schema.yml
Expand Up @@ -23124,7 +23124,6 @@ components:
- pk
- verbose_name
- verbose_name_plural
- verification_keys
OAuth2ProviderRequest:
type: object
description: OAuth2Provider Serializer
Expand Down Expand Up @@ -23198,7 +23197,6 @@ components:
required:
- authorization_flow
- name
- verification_keys
OAuth2ProviderSetupURLs:
type: object
description: OAuth2 Provider Metadata serializer
Expand Down
14 changes: 7 additions & 7 deletions web/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/package.json
Expand Up @@ -59,7 +59,7 @@
"@babel/preset-typescript": "^7.16.7",
"@formatjs/intl-listformat": "^6.5.3",
"@fortawesome/fontawesome-free": "^6.1.1",
"@goauthentik/api": "^2022.3.3-1648679473",
"@goauthentik/api": "^2022.3.3-1648750781",
"@jackfranklin/rollup-plugin-markdown": "^0.3.0",
"@lingui/cli": "^3.13.2",
"@lingui/core": "^3.13.2",
Expand Down
2 changes: 2 additions & 0 deletions website/docs/providers/oauth2/client_credentials.md
Expand Up @@ -2,6 +2,8 @@

Client credentials can be used for machine-to-machine communication authentication. Clients can authenticate themselves using service-accounts; standard client_id + client_secret is not sufficient. This behavior is due to providers only being able to have a single secret at any given time.

Note that authentik does treat a grant type of `password` the same as `client_credentials` to support applications which rely on a password grant.

### Static authentication

Hence identification is based on service-accounts, and authentication is based on App-password tokens. These objects can be created in a single step using the *Create Service account* function.
Expand Down

0 comments on commit 11132c0

Please sign in to comment.