Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: OAuth provider support #1010

Merged
merged 56 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
f4cb54d
fix: tenant config
sattvikc Jun 27, 2024
d88e411
fix: api permissions and telemetry update
sattvikc Jun 27, 2024
4b599eb
fix: totp length validation
sattvikc Jun 27, 2024
e9999f5
fix: accept api key via authorization header
sattvikc Jun 27, 2024
690166f
fix: cache control header for jwks endpoint
sattvikc Jun 27, 2024
cad6a2b
fix: tests
sattvikc Jun 28, 2024
e456b70
fix: for dashboard
sattvikc Jul 1, 2024
4f7bab6
fix: remove unused import
sattvikc Jul 1, 2024
b8a6215
fix: remove unused import
sattvikc Jul 1, 2024
1b70227
fix: providers non null
sattvikc Jul 2, 2024
3d16e01
fix: tests
sattvikc Jul 2, 2024
a63979c
fix: pr comments
sattvikc Jul 3, 2024
d677a58
fix: pr comments
sattvikc Jul 5, 2024
dea8465
fix: pr comments
sattvikc Jul 5, 2024
48212a3
fix: pr comments
sattvikc Jul 5, 2024
a7241ec
fix: improve core config normalisation
sattvikc Jul 5, 2024
9de5e82
fix: more tests
sattvikc Jul 8, 2024
61ebbe2
fix: more tests
sattvikc Jul 8, 2024
7fca254
fix: clean up core config
sattvikc Jul 8, 2024
fadc4b9
Merge branch '9.1' into feat/mt-dashboard
rishabhpoddar Jul 8, 2024
3a7beba
fix: pr comments
sattvikc Jul 8, 2024
404edaf
fix: more test
sattvikc Jul 8, 2024
0997638
adds config in config.yaml
rishabhpoddar Jul 8, 2024
3e1e5a5
reformates code
rishabhpoddar Jul 8, 2024
36fa29e
Merge branch '9.1' into feat/mt-dashboard
rishabhpoddar Jul 8, 2024
b4cdd5a
reformats code
rishabhpoddar Jul 8, 2024
ce7a5ea
Merge branch 'feat/mt-dashboard' into feat/oauth-provider-base
rishabhpoddar Jul 8, 2024
cba013e
modifies changelog
rishabhpoddar Jul 9, 2024
e7766a6
small changes
rishabhpoddar Jul 9, 2024
049a885
adds one more config for admin vs public service
rishabhpoddar Jul 9, 2024
67b6de7
starts working on authorization endpoint
rishabhpoddar Jul 9, 2024
04cebd0
Merge branch '9.1' into feat/oauth-provider-base
rishabhpoddar Jul 9, 2024
9a6248f
removes unnecesssary files
rishabhpoddar Jul 9, 2024
8bfd5c0
Merge branch '9.1' into feat/oauth-provider-base
rishabhpoddar Jul 29, 2024
02b5917
Oauth - WIP (#1018)
tamassoltesz Aug 5, 2024
7e98ed2
Merge branch '9.1' into feat/oauth-provider-base
rishabhpoddar Aug 5, 2024
aee7e88
Feature: oauth update client api (#1020)
tamassoltesz Aug 5, 2024
611e4e7
fix: merge with latest (#1028)
sattvikc Aug 20, 2024
6b403c6
Merge branch '9.2' into feat/oauth-provider-base
sattvikc Aug 20, 2024
2ea8d10
feat: hydra integration for auth, token and few more endpoints (#1032)
sattvikc Sep 25, 2024
6f225c5
fix: logout apis (#1047)
sattvikc Sep 27, 2024
eedbc91
fix: tests (#1051)
sattvikc Sep 27, 2024
3547399
Merge branch '9.2' into merge-latest
sattvikc Oct 2, 2024
f1abf7f
Merge pull request #1053 from supertokens/merge-latest
sattvikc Oct 2, 2024
4ab6d2b
fix: versioning and cleanup
sattvikc Oct 2, 2024
0f789a3
fix: http revert
sattvikc Oct 2, 2024
6fedd19
fix: http revert
sattvikc Oct 2, 2024
0e1075e
fix: rename / refactor
sattvikc Oct 2, 2024
2048aff
revert
sattvikc Oct 2, 2024
1100e3f
revert
sattvikc Oct 2, 2024
5c482ee
fix: test, cleanup and changelog
sattvikc Oct 2, 2024
fdc219e
revert
sattvikc Oct 2, 2024
e211521
fix: constraints
sattvikc Oct 4, 2024
020000f
fix: constraints
sattvikc Oct 4, 2024
296c582
fix: constraints
sattvikc Oct 4, 2024
8cb8f72
fix: constraints
sattvikc Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 44 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,40 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
## [Unreleased]

## [9.3.0]

### Changes

- Adds support for OAuth2
- Added new feature in license key: `OAUTH`
- Adds new core config:
- `oauth_provider_public_service_url`
- `oauth_provider_admin_service_url`
- `oauth_provider_consent_login_base_url`
- `oauth_provider_url_configured_in_oauth_provider`
- Adds following APIs:
- POST `/recipe/oauth/clients`
- PUT `/recipe/oauth/clients`
- GET `/recipe/oauth/clients`
- GET `/recipe/oauth/clients/list`
- POST `/recipe/oauth/clients/remove`
- GET `/recipe/oauth/auth/requests/consent`
- PUT `/recipe/oauth/auth/requests/consent/accept`
- PUT `/recipe/oauth/auth/requests/consent/reject`
- GET `/recipe/oauth/auth/requests/login`
- PUT `/recipe/oauth/auth/requests/login/accept`
- PUT `/recipe/oauth/auth/requests/login/reject`
- GET `/recipe/oauth/auth/requests/logout`
- PUT `/recipe/oauth/auth/requests/logout/accept`
- PUT `/recipe/oauth/auth/requests/logout/reject`
- POST `/recipe/oauth/auth`
- POST `/recipe/oauth/token`
- POST `/recipe/oauth/introspect`
- POST `/recipe/oauth/session/revoke`
- POST `/recipe/oauth/token/revoke`
- POST `/recipe/oauth/tokens/revoke`

## [9.2.2] - 2024-09-04

Expand Down Expand Up @@ -160,17 +193,19 @@ Make sure the core is already upgraded to version 8.0.0 before migrating
If using PostgreSQL

```sql
ALTER TABLE totp_user_devices ADD COLUMN IF NOT EXISTS created_at BIGINT default 0;
ALTER TABLE totp_user_devices
ALTER COLUMN created_at DROP DEFAULT;
ALTER TABLE totp_user_devices
ADD COLUMN IF NOT EXISTS created_at BIGINT default 0;
ALTER TABLE totp_user_devices
ALTER COLUMN created_at DROP DEFAULT;
```

If using MySQL

```sql
ALTER TABLE totp_user_devices ADD COLUMN created_at BIGINT UNSIGNED default 0;
ALTER TABLE totp_user_devices
ALTER COLUMN created_at DROP DEFAULT;
ALTER TABLE totp_user_devices
ADD COLUMN created_at BIGINT UNSIGNED default 0;
ALTER TABLE totp_user_devices
ALTER COLUMN created_at DROP DEFAULT;
DROP INDEX all_auth_recipe_users_pagination_index2 ON all_auth_recipe_users;
DROP INDEX all_auth_recipe_users_pagination_index4 ON all_auth_recipe_users;
```
Expand Down Expand Up @@ -222,8 +257,8 @@ For MySQL:
ALTER TABLE user_roles DROP FOREIGN KEY user_roles_ibfk_1;
ALTER TABLE user_roles DROP FOREIGN KEY user_roles_ibfk_2;
ALTER TABLE user_roles
ADD FOREIGN KEY (app_id, tenant_id)
REFERENCES tenants (app_id, tenant_id) ON DELETE CASCADE;
ADD FOREIGN KEY (app_id, tenant_id)
REFERENCES tenants (app_id, tenant_id) ON DELETE CASCADE;
```

## [7.0.18] - 2024-02-19
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ compileTestJava { options.encoding = "UTF-8" }
// }
//}

version = "9.2.2"
version = "9.3.0"


repositories {
Expand Down
16 changes: 16 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,19 @@ core_config_version: 0
# (OPTIONAL | Default: null) string value. If specified, the supertokens service will only load the specified CUD even
# if there are more CUDs in the database and block all other CUDs from being used from this instance.
# supertokens_saas_load_only_cud:

# (OPTIONAL | Default: null) string value. If specified, the core uses this URL to connect to the OAuth provider
# public service.
# oauth_provider_public_service_url:

# (OPTIONAL | Default: null) string value. If specified, the core uses this URL to connect to the OAuth provider admin
# service.
# oauth_provider_admin_service_url:

# (OPTIONAL | Default: null) string value. If specified, the core uses this URL to replace the default
# consent and login URLs to {apiDomain}.
# oauth_provider_consent_login_base_url:

# (OPTIONAL | Default: oauth_provider_public_service_url) If specified, the core uses this URL to parse responses from
# the oauth provider when the oauth provider's internal address differs from the known public provider address.
# oauth_provider_url_configured_in_oauth_provider:
3 changes: 2 additions & 1 deletion coreDriverInterfaceSupported.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"3.1",
"4.0",
"5.0",
"5.1"
"5.1",
"5.2"
]
}
16 changes: 16 additions & 0 deletions devConfig.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,19 @@ disable_telemetry: true
# (OPTIONAL | Default: null) string value. If specified, the supertokens service will only load the specified CUD even
# if there are more CUDs in the database and block all other CUDs from being used from this instance.
# supertokens_saas_load_only_cud:

# (OPTIONAL | Default: null) string value. If specified, the core uses this URL to connect to the OAuth provider
# public service.
# oauth_provider_public_service_url:

# (OPTIONAL | Default: null) string value. If specified, the core uses this URL to connect to the OAuth provider admin
# service.
# oauth_provider_admin_service_url:

# (OPTIONAL | Default: null) string value. If specified, the core uses this URL to replace the default
# consent and login URLs to {apiDomain}.
# oauth_provider_consent_login_base_url:

# (OPTIONAL | Default: oauth_provider_public_service_url) If specified, the core uses this URL to parse responses from
# the oauth provider when the oauth provider's internal address differs from the known public provider address.
# oauth_provider_url_configured_in_oauth_provider:
28 changes: 28 additions & 0 deletions ee/src/main/java/io/supertokens/ee/EEFeatureFlag.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.supertokens.pluginInterface.KeyValueInfo;
import io.supertokens.pluginInterface.STORAGE_TYPE;
import io.supertokens.pluginInterface.Storage;
import io.supertokens.pluginInterface.StorageUtils;
import io.supertokens.pluginInterface.authRecipe.AuthRecipeStorage;
import io.supertokens.pluginInterface.dashboard.sqlStorage.DashboardSQLStorage;
import io.supertokens.pluginInterface.exceptions.StorageQueryException;
Expand All @@ -32,6 +33,7 @@
import io.supertokens.pluginInterface.multitenancy.TenantIdentifier;
import io.supertokens.pluginInterface.multitenancy.ThirdPartyConfig;
import io.supertokens.pluginInterface.multitenancy.exceptions.TenantOrAppNotFoundException;
import io.supertokens.pluginInterface.oauth.OAuthStorage;
import io.supertokens.pluginInterface.session.sqlStorage.SessionSQLStorage;
import io.supertokens.storageLayer.StorageLayer;
import io.supertokens.utils.Utils;
Expand Down Expand Up @@ -348,6 +350,28 @@ private JsonObject getAccountLinkingStats() throws StorageQueryException, Tenant
return result;
}

private JsonObject getOAuthStats() throws StorageQueryException, TenantOrAppNotFoundException {
JsonObject result = new JsonObject();

OAuthStorage oAuthStorage = StorageUtils.getOAuthStorage(StorageLayer.getStorage(
this.appIdentifier.getAsPublicTenantIdentifier(), main));

result.addProperty("totalNumberOfClients", oAuthStorage.countTotalNumberOfOAuthClients(appIdentifier));
result.addProperty("numberOfClientCredentialsOnlyClients", oAuthStorage.countTotalNumberOfClientCredentialsOnlyOAuthClients(appIdentifier));
result.addProperty("numberOfM2MTokensAlive", oAuthStorage.countTotalNumberOfOAuthM2MTokensAlive(appIdentifier));

long now = System.currentTimeMillis();
JsonArray tokensCreatedArray = new JsonArray();
for (int i = 1; i <= 31; i++) {
long timestamp = now - (i * 24 * 60 * 60 * 1000L);
int numberOfTokensCreated = oAuthStorage.countTotalNumberOfOAuthM2MTokensCreatedSince(this.appIdentifier, timestamp);
tokensCreatedArray.add(new JsonPrimitive(numberOfTokensCreated));
}
result.add("numberOfM2MTokensCreated", tokensCreatedArray);

return result;
}

private JsonArray getMAUs() throws StorageQueryException, TenantOrAppNotFoundException {
JsonArray mauArr = new JsonArray();
long now = System.currentTimeMillis();
Expand Down Expand Up @@ -405,6 +429,10 @@ public JsonObject getPaidFeatureStats() throws StorageQueryException, TenantOrAp
if (feature == EE_FEATURES.SECURITY) {
usageStats.add(EE_FEATURES.SECURITY.toString(), new JsonObject());
}

if (feature == EE_FEATURES.OAUTH) {
usageStats.add(EE_FEATURES.OAUTH.toString(), getOAuthStats());
}
}

usageStats.add("maus", getMAUs());
Expand Down
2 changes: 1 addition & 1 deletion pluginInterfaceSupported.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"_comment": "contains a list of plugin interfaces branch names that this core supports",
"versions": [
"6.2"
"6.3"
]
}
3 changes: 3 additions & 0 deletions src/main/java/io/supertokens/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import io.supertokens.config.Config;
import io.supertokens.config.CoreConfig;
import io.supertokens.cronjobs.Cronjobs;
import io.supertokens.cronjobs.cleanupOAuthRevokeListAndChallenges.CleanupOAuthRevokeListAndChallenges;
import io.supertokens.cronjobs.deleteExpiredAccessTokenSigningKeys.DeleteExpiredAccessTokenSigningKeys;
import io.supertokens.cronjobs.deleteExpiredDashboardSessions.DeleteExpiredDashboardSessions;
import io.supertokens.cronjobs.deleteExpiredEmailVerificationTokens.DeleteExpiredEmailVerificationTokens;
Expand Down Expand Up @@ -256,6 +257,8 @@ private void init() throws IOException, StorageQueryException {
// starts DeleteExpiredAccessTokenSigningKeys cronjob if the access token signing keys can change
Cronjobs.addCronjob(this, DeleteExpiredAccessTokenSigningKeys.init(this, uniqueUserPoolIdsTenants));

Cronjobs.addCronjob(this, CleanupOAuthRevokeListAndChallenges.init(this, uniqueUserPoolIdsTenants));

// this is to ensure tenantInfos are in sync for the new cron job as well
MultitenancyHelper.getInstance(this).refreshCronjobs();

Expand Down
1 change: 0 additions & 1 deletion src/main/java/io/supertokens/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import io.supertokens.Main;
Expand Down
Loading
Loading