Castlecraft extensions for frappe microservice development.
It requires Authorization Server with following features:
- Token Introspection Endpoint
- ID Token verification using jwks uri
After installation of this app, request to frappe app can be made using access_token
generated by central server.
Note: Works on version 13 onwards.
bench get-app castlecraft https://gitlab.com/castlecraft/cfe.git
bench --site <site-name> install-app castlecraft
Make following changes in site_config.json
as per your setup:
{
...
// For Introspection
"castlecraft_auth_header_enabled": 1,
"castlecraft_auth_introspect_bearer_enabled": 1,
"castlecraft_client_id": "client_id",
"castlecraft_client_secret": "client_secret",
"castlecraft_introspect_token_key": "access_token",
"castlecraft_introspect_url": "https://accounts.example.com/oauth2/introspection",
"castlecraft_fetch_userinfo": 1,
"castlecraft_userinfo_url": "https://accounts.example.com/oauth2/profile",
// For id_token verification
"castlecraft_auth_jwt_verify_bearer_enabled": 1,
"castlecraft_jwks_url": "https://accounts.example.com/.well-known/jwks",
"castlecraft_allowed_aud": ["client_id_or_allowed_aud_claim", "abe31e1c-c6d0-4415-8aa9-ca674685fa00"],
// Common
"castlecraft_create_user_on_auth_enabled": 1,
"castlecraft_email_key": "preferred_username",
"castlecraft_first_name_key": "given_name",
"castlecraft_full_name_key": "name",
"castlecraft_username_key": "employee_id",
"castlecraft_default_roles": ["Blogger"]
...
}
castlecraft_auth_introspect_bearer_enabled
: When set to1
, token is introspected to validate user.castlecraft_auth_header_enabled
: When set to1
, token is introspection endpoint uses basic auth withclient_id
andclient_secret
.castlecraft_client_id
: Registeredclient_id
.castlecraft_client_secret
: Registeredclient_secret
.castlecraft_introspect_url
: Token introspection url.castlecraft_introspect_token_key
: Key used to pass token to introspection endpoint. Defaults totoken
. Example request will havetoken=abc123
.castlecraft_fetch_userinfo
: If set to1
user information will be fetched from userinfo instead of introspection responsecastlecraft_userinfo_url
: Userinfo url. required ifcastlecraft_fetch_userinfo
is used.
castlecraft_auth_jwt_verify_bearer_enabled
: When set to1
, token is assumed to be jwt and verified using JWKS.castlecraft_jwks_url
: JWKS URL required in casecastlecraft_auth_jwt_verify_bearer_enabled
is set to1
castlecraft_allowed_aud
: string or array of strings with validaud
used to verifyid_token
. Default to empty array[]
.
castlecraft_create_user_on_auth_enabled
: When set to1
, user with no roles will be created if not found in system.castlecraft_email_key
: OIDC Claim or key to use for getting user's email. Default isemail
.castlecraft_first_name_key
: OIDC Claim or key to use for getting user's first name. Default isgiven_name
.castlecraft_full_name_key
: OIDC Claim or key to use for getting user's full name. Default isname
.castlecraft_username_key
: OIDC Claim or key to use for setting user'susername
. Default is not set.castlecraft_default_roles
: Array of roles to add to user on creation. Default is[]
.castlecraft_enable_log
: If set to1
,Error Log
will be created on auth errors.
Note: Either set castlecraft_auth_introspect_bearer_enabled
or castlecraft_auth_jwt_verify_bearer_enabled
, NOT both. In case both are set, auth castlecraft_auth_introspect_bearer_enabled
will be considered.
Backchannel logout endpoint: /api/method/castlecraft.services.oauth2.back_channel_logout
. Example: https://example.com/api/method/castlecraft.services.oauth2.back_channel_logout
Copyright 2023 Castlecraft Ecommerce Pvt. Ltd.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.