From 3deea900a754d4a627612acd6fa3bdf1b8b05a36 Mon Sep 17 00:00:00 2001 From: Pulkit Gupta <92841386+pulguptaAdobe@users.noreply.github.com> Date: Mon, 15 Jan 2024 17:58:09 +0530 Subject: [PATCH 1/7] `aio-lib-osgi` added export instruction for auth package (#202) Recently we upgraded to 1.1.12 version of the sdk and started using com.adobe.aio.auth but we were not able to start our bundle on AEM since the artifact aio-lib-osgi is not exporting this package. Added this package in the export list so that the dependent bundles can access the classes of this package. --- aem/lib_osgi/src/main/bnd/aio-lib-osgi.bnd | 1 + 1 file changed, 1 insertion(+) diff --git a/aem/lib_osgi/src/main/bnd/aio-lib-osgi.bnd b/aem/lib_osgi/src/main/bnd/aio-lib-osgi.bnd index 46c46a6a..14aabd8c 100644 --- a/aem/lib_osgi/src/main/bnd/aio-lib-osgi.bnd +++ b/aem/lib_osgi/src/main/bnd/aio-lib-osgi.bnd @@ -32,6 +32,7 @@ Import-Package: \ com.fasterxml.jackson.databind.type;version="[2.9,3)",\ * Export-Package: com.adobe.aio.workspace;version="${project.version}";provide:=true,\ + com.adobe.aio.auth;version="${project.version}";provide:=true,\ com.adobe.aio.exception;version="${project.version}";provide:=true,\ com.adobe.aio.util;version="${project.version}";provide:=true,\ com.adobe.aio.ims;version="${project.version}";provide:=true,\ From 254138ca6f4105eaa8612d7de2d4b9aef9d396f4 Mon Sep 17 00:00:00 2001 From: hayatkha Date: Thu, 1 Aug 2024 14:34:47 +0530 Subject: [PATCH 2/7] Initial Commit --- .../internal/WorkspaceSupplierImpl.java | 1 + .../aem/workspace/ocd/WorkspaceConfig.java | 4 +++ .../com/adobe/aio/workspace/Workspace.java | 34 ++++++++++++++++--- .../adobe/aio/workspace/WorkspaceTest.java | 3 +- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/internal/WorkspaceSupplierImpl.java b/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/internal/WorkspaceSupplierImpl.java index aeaf2b93..aa50e6bd 100644 --- a/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/internal/WorkspaceSupplierImpl.java +++ b/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/internal/WorkspaceSupplierImpl.java @@ -92,6 +92,7 @@ private Map getAuthConfigMap( map.put(Workspace.TECHNICAL_ACCOUNT_ID, config.aio_technical_account_id()); map.put(Workspace.WORKSPACE_ID, config.aio_workspace_id()); map.put(Workspace.META_SCOPES, config.aio_meta_scopes()); + map.put(Workspace.OAUTH_SCOPES, config.aio_oauth_scopes()); return map; } diff --git a/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/ocd/WorkspaceConfig.java b/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/ocd/WorkspaceConfig.java index d54ff780..41e7cba2 100644 --- a/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/ocd/WorkspaceConfig.java +++ b/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/ocd/WorkspaceConfig.java @@ -26,6 +26,10 @@ description = "Comma separated list of metascopes associated with your API (`/s/event_receiver_api,/s/ent_adobeio_sdk` for instance) (project.workspace.details.credentials.jwt.meta_scopes)") String aio_meta_scopes() default "/s/ent_adobeio_sdk"; + @AttributeDefinition(name = "OAuth Scopes", + description = "Comma separated list of oauth scopes associated with your API (project.workspace.details.credentials.oauth_server_to_server.scopes)") + String aio_oauth_scopes(); + @AttributeDefinition(name = "IMS ORG ID", description = "Adobe IMS Organization ID as shown in your Adobe Developer Console workspace (project.org.ims_org_id)") String aio_ims_org_id(); diff --git a/core/src/main/java/com/adobe/aio/workspace/Workspace.java b/core/src/main/java/com/adobe/aio/workspace/Workspace.java index cd6986d5..40755d63 100644 --- a/core/src/main/java/com/adobe/aio/workspace/Workspace.java +++ b/core/src/main/java/com/adobe/aio/workspace/Workspace.java @@ -17,6 +17,7 @@ import com.adobe.aio.auth.Context; import com.adobe.aio.auth.JwtContext; +import com.adobe.aio.auth.OAuthContext; import com.adobe.aio.util.Constants; import java.security.PrivateKey; import java.util.Map; @@ -53,6 +54,8 @@ public class Workspace { @Deprecated public static final String META_SCOPES = "aio_meta_scopes"; + public static final String OAUTH_SCOPES = "aio_oauth_scopes"; + // workspace context related: private final String imsUrl; private final String imsOrgId; @@ -62,6 +65,8 @@ public class Workspace { private final String workspaceId; private final Context authContext; + private static boolean oAuthContext = false; + private Workspace(final String imsUrl, final String imsOrgId, final String apiKey, final String consumerOrgId, final String projectId, final String workspaceId, Context authContext) { @@ -202,6 +207,7 @@ public static class Builder { private JwtContext.Builder jwtbuilder; private Context authContext; + private OAuthContext.Builder oAuthBuilder; private Builder() { } @@ -254,6 +260,10 @@ public Builder clientSecret(final String clientSecret) { jwtbuilder = JwtContext.builder(); } jwtbuilder.clientSecret(clientSecret); + if(oAuthBuilder == null){ + oAuthBuilder = OAuthContext.builder(); + } + oAuthBuilder.clientSecret(clientSecret); return this; } @@ -270,6 +280,10 @@ public Builder addMetascope(final String metascope) { jwtbuilder = JwtContext.builder(); } jwtbuilder.addMetascope(metascope); + if(oAuthBuilder == null){ + oAuthBuilder = OAuthContext.builder(); + } + oAuthBuilder.addScope(metascope); return this; } @@ -289,10 +303,15 @@ public Builder configMap(final Map configMap) { .consumerOrgId(configMap.get(CONSUMER_ORG_ID)) .projectId(configMap.get(PROJECT_ID)) .workspaceId(configMap.get(WORKSPACE_ID)); - // For backwards compatibility - should this be kept? - jwtbuilder = JwtContext.builder(); - jwtbuilder.configMap(configMap); + if(StringUtils.isBlank(configMap.get(OAUTH_SCOPES))) { + jwtbuilder = JwtContext.builder(); + jwtbuilder.configMap(configMap); + } else { + oAuthBuilder = OAuthContext.builder(); + oAuthBuilder.configMap(configMap); + oAuthContext = true; + } return this; } @@ -314,10 +333,17 @@ public Workspace build() { if (authContext != null) { return new Workspace(imsUrl, imsOrgId, apiKey, consumerOrgId, projectId, workspaceId, authContext); } + if(oAuthBuilder == null) { + oAuthBuilder = OAuthContext.builder(); + } if (jwtbuilder == null) { jwtbuilder = JwtContext.builder(); } - return new Workspace(imsUrl, imsOrgId, apiKey, consumerOrgId, projectId, workspaceId, jwtbuilder.build()); + if(oAuthContext){ + return new Workspace(imsUrl, imsOrgId, apiKey, consumerOrgId, projectId, workspaceId, oAuthBuilder.build()); + } else { + return new Workspace(imsUrl, imsOrgId, apiKey, consumerOrgId, projectId, workspaceId, jwtbuilder.build()); + } } } } diff --git a/core/src/test/java/com/adobe/aio/workspace/WorkspaceTest.java b/core/src/test/java/com/adobe/aio/workspace/WorkspaceTest.java index 1661f6f7..42649105 100644 --- a/core/src/test/java/com/adobe/aio/workspace/WorkspaceTest.java +++ b/core/src/test/java/com/adobe/aio/workspace/WorkspaceTest.java @@ -18,6 +18,7 @@ import com.adobe.aio.auth.Context; import com.adobe.aio.auth.JwtContext; +import com.adobe.aio.auth.OAuthContext; import com.adobe.aio.util.Constants; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -141,7 +142,7 @@ public void jwtBackwardsCompat() throws Exception { .credentialId(JwtContext.CREDENTIAL_ID + TEST_VALUE) .technicalAccountId(JwtContext.TECHNICAL_ACCOUNT_ID + TEST_VALUE) .privateKey(privateKey) - .addMetascope(JwtContext.META_SCOPES + TEST_VALUE) + .addMetascope(OAuthContext.SCOPES + TEST_VALUE) .build(); assertEquals(actual, expected); assertEquals(actual.hashCode(), expected.hashCode()); From aefed79af39874293f230a8bc23f5a1ee3169ae2 Mon Sep 17 00:00:00 2001 From: hayatkha Date: Thu, 1 Aug 2024 20:03:30 +0530 Subject: [PATCH 3/7] Allowing backward compatibility with JWT --- core/src/main/java/com/adobe/aio/workspace/Workspace.java | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/main/java/com/adobe/aio/workspace/Workspace.java b/core/src/main/java/com/adobe/aio/workspace/Workspace.java index 40755d63..9f490129 100644 --- a/core/src/main/java/com/adobe/aio/workspace/Workspace.java +++ b/core/src/main/java/com/adobe/aio/workspace/Workspace.java @@ -307,6 +307,7 @@ public Builder configMap(final Map configMap) { if(StringUtils.isBlank(configMap.get(OAUTH_SCOPES))) { jwtbuilder = JwtContext.builder(); jwtbuilder.configMap(configMap); + oAuthContext = false; } else { oAuthBuilder = OAuthContext.builder(); oAuthBuilder.configMap(configMap); From 8a64a06d0e70bcfd20d4a21d3b6a7f5e83c01667 Mon Sep 17 00:00:00 2001 From: hayatkha Date: Wed, 7 Aug 2024 14:40:08 +0530 Subject: [PATCH 4/7] Review Comments Incorporated --- .../internal/WorkspaceSupplierImpl.java | 3 +- .../com/adobe/aio/workspace/Workspace.java | 16 ++++----- .../com/adobe/aio/auth/OAuthContextTest.java | 2 +- .../adobe/aio/workspace/WorkspaceTest.java | 4 +-- .../test/resources/workspace.oauth.properties | 33 +++++++++++++++++++ core/src/test/resources/workspace.properties | 3 -- 6 files changed, 44 insertions(+), 17 deletions(-) create mode 100644 core/src/test/resources/workspace.oauth.properties diff --git a/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/internal/WorkspaceSupplierImpl.java b/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/internal/WorkspaceSupplierImpl.java index aa50e6bd..9e8e63dd 100644 --- a/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/internal/WorkspaceSupplierImpl.java +++ b/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/internal/WorkspaceSupplierImpl.java @@ -14,6 +14,7 @@ import com.adobe.aio.aem.status.Status; import com.adobe.aio.aem.workspace.WorkspaceSupplier; import com.adobe.aio.aem.workspace.ocd.WorkspaceConfig; +import com.adobe.aio.auth.OAuthContext; import com.adobe.aio.ims.util.PrivateKeyBuilder; import com.adobe.aio.workspace.Workspace; import java.security.PrivateKey; @@ -92,7 +93,7 @@ private Map getAuthConfigMap( map.put(Workspace.TECHNICAL_ACCOUNT_ID, config.aio_technical_account_id()); map.put(Workspace.WORKSPACE_ID, config.aio_workspace_id()); map.put(Workspace.META_SCOPES, config.aio_meta_scopes()); - map.put(Workspace.OAUTH_SCOPES, config.aio_oauth_scopes()); + map.put(OAuthContext.SCOPES, config.aio_oauth_scopes()); return map; } diff --git a/core/src/main/java/com/adobe/aio/workspace/Workspace.java b/core/src/main/java/com/adobe/aio/workspace/Workspace.java index 9f490129..fa3c2837 100644 --- a/core/src/main/java/com/adobe/aio/workspace/Workspace.java +++ b/core/src/main/java/com/adobe/aio/workspace/Workspace.java @@ -54,8 +54,6 @@ public class Workspace { @Deprecated public static final String META_SCOPES = "aio_meta_scopes"; - public static final String OAUTH_SCOPES = "aio_oauth_scopes"; - // workspace context related: private final String imsUrl; private final String imsOrgId; @@ -65,8 +63,6 @@ public class Workspace { private final String workspaceId; private final Context authContext; - private static boolean oAuthContext = false; - private Workspace(final String imsUrl, final String imsOrgId, final String apiKey, final String consumerOrgId, final String projectId, final String workspaceId, Context authContext) { @@ -304,14 +300,12 @@ public Builder configMap(final Map configMap) { .projectId(configMap.get(PROJECT_ID)) .workspaceId(configMap.get(WORKSPACE_ID)); // For backwards compatibility - should this be kept? - if(StringUtils.isBlank(configMap.get(OAUTH_SCOPES))) { + if(StringUtils.isBlank(configMap.get(OAuthContext.SCOPES))) { jwtbuilder = JwtContext.builder(); jwtbuilder.configMap(configMap); - oAuthContext = false; } else { oAuthBuilder = OAuthContext.builder(); oAuthBuilder.configMap(configMap); - oAuthContext = true; } return this; } @@ -334,16 +328,18 @@ public Workspace build() { if (authContext != null) { return new Workspace(imsUrl, imsOrgId, apiKey, consumerOrgId, projectId, workspaceId, authContext); } - if(oAuthBuilder == null) { + if (oAuthBuilder == null) { oAuthBuilder = OAuthContext.builder(); } if (jwtbuilder == null) { jwtbuilder = JwtContext.builder(); } - if(oAuthContext){ + if (jwtbuilder != null && jwtbuilder.build().getPrivateKey() != null) { + return new Workspace(imsUrl, imsOrgId, apiKey, consumerOrgId, projectId, workspaceId, jwtbuilder.build()); + } else if (oAuthBuilder != null) { return new Workspace(imsUrl, imsOrgId, apiKey, consumerOrgId, projectId, workspaceId, oAuthBuilder.build()); } else { - return new Workspace(imsUrl, imsOrgId, apiKey, consumerOrgId, projectId, workspaceId, jwtbuilder.build()); + throw new IllegalStateException("Missing auth confiugration, set either jwt or oauth..."); } } } diff --git a/core/src/test/java/com/adobe/aio/auth/OAuthContextTest.java b/core/src/test/java/com/adobe/aio/auth/OAuthContextTest.java index 778a3762..731c3483 100644 --- a/core/src/test/java/com/adobe/aio/auth/OAuthContextTest.java +++ b/core/src/test/java/com/adobe/aio/auth/OAuthContextTest.java @@ -8,7 +8,7 @@ public class OAuthContextTest { - private static final String TEST_PROPERTIES = "workspace.properties"; + private static final String TEST_PROPERTIES = "workspace.oauth.properties"; private static final String TEST_VALUE = "_changeMe"; private static OAuthContext expected; diff --git a/core/src/test/java/com/adobe/aio/workspace/WorkspaceTest.java b/core/src/test/java/com/adobe/aio/workspace/WorkspaceTest.java index 42649105..46a31c6b 100644 --- a/core/src/test/java/com/adobe/aio/workspace/WorkspaceTest.java +++ b/core/src/test/java/com/adobe/aio/workspace/WorkspaceTest.java @@ -130,7 +130,7 @@ public void projectUrl() { } @Test - public void jwtBackwardsCompat() throws Exception { + public void jwtBackwardsCompatible() throws Exception { Workspace actual = Workspace.builder() .imsUrl(Constants.IMS_URL) .imsOrgId(Workspace.IMS_ORG_ID + TEST_VALUE) @@ -142,7 +142,7 @@ public void jwtBackwardsCompat() throws Exception { .credentialId(JwtContext.CREDENTIAL_ID + TEST_VALUE) .technicalAccountId(JwtContext.TECHNICAL_ACCOUNT_ID + TEST_VALUE) .privateKey(privateKey) - .addMetascope(OAuthContext.SCOPES + TEST_VALUE) + .addMetascope(JwtContext.META_SCOPES + TEST_VALUE) .build(); assertEquals(actual, expected); assertEquals(actual.hashCode(), expected.hashCode()); diff --git a/core/src/test/resources/workspace.oauth.properties b/core/src/test/resources/workspace.oauth.properties new file mode 100644 index 00000000..1472e991 --- /dev/null +++ b/core/src/test/resources/workspace.oauth.properties @@ -0,0 +1,33 @@ +# +# Copyright 2017 Adobe. All rights reserved. +# This file is licensed to you under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. You may obtain a copy +# of the License at http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under +# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS +# OF ANY KIND, either express or implied. See the License for the specific language +# governing permissions and limitations under the License. +# + +# aio_project_id = your Adobe Developer Console project id (project.id) +aio_project_id=aio_project_id_changeMe +# aio_consumer_org_id = your Adobe Developer Console consumer orgnaization id (project.org.id) +aio_consumer_org_id=aio_consumer_org_id_changeMe +# aio_ims_org_id = your Adobe Developer Console IMS Organization ID (project.org.ims_org_id) +aio_ims_org_id=aio_ims_org_id_changeMe +# aio_workspace_id = your Adobe Developer Console workspace Id (project.workspace.id) +aio_workspace_id=aio_workspace_id_changeMe +# aio_credential_id = your Adobe Developer Console jwt credential id (project.workspace.details.credentials[i].id) +aio_credential_id=aio_credential_id_changeMe +# aio_client_secret = your Adobe Developer Console jwt or OAuth credential client secret (project.workspace.details.credentials[i].jwt.client_secret) +aio_client_secret=aio_client_secret_changeMe +# aio_api_key = your Adobe Developer Console jwt credential API Key (or Client ID) (project.workspace.details.credentials[i].jwt.client_id +aio_api_key=aio_api_key_changeMe +# aio_technical_account_id = your Adobe Developer Console jwt credential technical account id (project.workspace.details.credentials[i].jwt.technical_account_id) +aio_technical_account_id=aio_technical_account_id_changeMe +# aio_oauth_scopes : comma separated list of scopes associated with your API, see your Adobe Developer Console OAuth credential scopes +# sample aio_meta_scopes: openid, AdobeID, read_organizations +aio_oauth_scopes=aio_oauth_scopes_changeMe + + diff --git a/core/src/test/resources/workspace.properties b/core/src/test/resources/workspace.properties index bd16d06d..0bfcbef8 100644 --- a/core/src/test/resources/workspace.properties +++ b/core/src/test/resources/workspace.properties @@ -30,8 +30,5 @@ aio_meta_scopes=aio_meta_scopes_changeMe # aio_technical_account_id = your Adobe Developer Console jwt credential technical account id (project.workspace.details.credentials[i].jwt.technical_account_id) aio_technical_account_id=aio_technical_account_id_changeMe -# aio_oauth_scopes : comma separated list of scopes associated with your API, see your Adobe Developer Console OAuth credential scopes -# sample aio_meta_scopes: openid, AdobeID, read_organizations -aio_oauth_scopes=aio_oauth_scopes_changeMe From a331ea8c0ea0fe8a345fcb7e0b626bb70de1822c Mon Sep 17 00:00:00 2001 From: hayatkha Date: Wed, 7 Aug 2024 18:04:19 +0530 Subject: [PATCH 5/7] Review Comment Incorporated --- aem/core_aem/README.md | 1 + .../aem/workspace/ocd/WorkspaceConfig.java | 6 ++-- .../com/adobe/aio/workspace/Workspace.java | 13 +------- .../com/adobe/aio/auth/OAuthContextTest.java | 2 +- .../adobe/aio/workspace/WorkspaceTest.java | 1 - .../test/resources/workspace.oauth.properties | 33 ------------------- core/src/test/resources/workspace.properties | 4 ++- 7 files changed, 9 insertions(+), 51 deletions(-) delete mode 100644 core/src/test/resources/workspace.oauth.properties diff --git a/aem/core_aem/README.md b/aem/core_aem/README.md index 2fea19e0..ea6b6b0d 100644 --- a/aem/core_aem/README.md +++ b/aem/core_aem/README.md @@ -22,6 +22,7 @@ service looks up the following OSGI configuration keys: * `aio.api.key` your Adobe Developer Console jwt credential API Key (or Client ID) (`project.workspace.details.credentials[i].jwt.client_id`) * `aio.client.secret` your Adobe Developer Console jwt credential client secret (`project.workspace.details.credentials[i].jwt.client_secret`) * `aio.meta.scopes` a comma separated list of metascopes associated with your API, see your Adobe Developer Console jwt credential metascopes (`project.workspace.details.credentials[i].jwt.meta_scopes`) +* `aio_oauth_scopes` a comma separated list of OAuth scopes associated with your API, see your Adobe Developer Console OAuth scopes (project.workspace.details.credentials[i].oauth_server_to_server.scopes) * `aio.technical.account.id` your Adobe Developer Console jwt credential technical account id (`project.workspace.details.credentials[i].jwt.technical_account_id`) * `aio.encoded.pkcs8` your private key (in a base64 encoded pkcs8 format) see below diff --git a/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/ocd/WorkspaceConfig.java b/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/ocd/WorkspaceConfig.java index 41e7cba2..ea029b1e 100644 --- a/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/ocd/WorkspaceConfig.java +++ b/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/ocd/WorkspaceConfig.java @@ -22,12 +22,12 @@ description = "Adobe IMS URL: prod: https://ims-na1.adobelogin.com | stage: https://ims-na1-stg1.adobelogin.com") String aio_ims_url() default "https://ims-na1.adobelogin.com"; - @AttributeDefinition(name = "Meta Scopes", - description = "Comma separated list of metascopes associated with your API (`/s/event_receiver_api,/s/ent_adobeio_sdk` for instance) (project.workspace.details.credentials.jwt.meta_scopes)") + @AttributeDefinition(name = "JWT Meta Scopes", + description = "Comma separated list of metascopes associated with your API (`/s/event_receiver_api,/s/ent_adobeio_sdk` for instance) (project.workspace.details.credentials.jwt.meta_scopes), to be used with JWT.") String aio_meta_scopes() default "/s/ent_adobeio_sdk"; @AttributeDefinition(name = "OAuth Scopes", - description = "Comma separated list of oauth scopes associated with your API (project.workspace.details.credentials.oauth_server_to_server.scopes)") + description = "Comma separated String. list of oauth scopes associated with your API (project.workspace.details.credentials.oauth_server_to_server.scopes)") String aio_oauth_scopes(); @AttributeDefinition(name = "IMS ORG ID", diff --git a/core/src/main/java/com/adobe/aio/workspace/Workspace.java b/core/src/main/java/com/adobe/aio/workspace/Workspace.java index fa3c2837..743094f7 100644 --- a/core/src/main/java/com/adobe/aio/workspace/Workspace.java +++ b/core/src/main/java/com/adobe/aio/workspace/Workspace.java @@ -256,10 +256,6 @@ public Builder clientSecret(final String clientSecret) { jwtbuilder = JwtContext.builder(); } jwtbuilder.clientSecret(clientSecret); - if(oAuthBuilder == null){ - oAuthBuilder = OAuthContext.builder(); - } - oAuthBuilder.clientSecret(clientSecret); return this; } @@ -279,7 +275,6 @@ public Builder addMetascope(final String metascope) { if(oAuthBuilder == null){ oAuthBuilder = OAuthContext.builder(); } - oAuthBuilder.addScope(metascope); return this; } @@ -328,13 +323,7 @@ public Workspace build() { if (authContext != null) { return new Workspace(imsUrl, imsOrgId, apiKey, consumerOrgId, projectId, workspaceId, authContext); } - if (oAuthBuilder == null) { - oAuthBuilder = OAuthContext.builder(); - } - if (jwtbuilder == null) { - jwtbuilder = JwtContext.builder(); - } - if (jwtbuilder != null && jwtbuilder.build().getPrivateKey() != null) { + if (jwtbuilder != null) { return new Workspace(imsUrl, imsOrgId, apiKey, consumerOrgId, projectId, workspaceId, jwtbuilder.build()); } else if (oAuthBuilder != null) { return new Workspace(imsUrl, imsOrgId, apiKey, consumerOrgId, projectId, workspaceId, oAuthBuilder.build()); diff --git a/core/src/test/java/com/adobe/aio/auth/OAuthContextTest.java b/core/src/test/java/com/adobe/aio/auth/OAuthContextTest.java index 731c3483..778a3762 100644 --- a/core/src/test/java/com/adobe/aio/auth/OAuthContextTest.java +++ b/core/src/test/java/com/adobe/aio/auth/OAuthContextTest.java @@ -8,7 +8,7 @@ public class OAuthContextTest { - private static final String TEST_PROPERTIES = "workspace.oauth.properties"; + private static final String TEST_PROPERTIES = "workspace.properties"; private static final String TEST_VALUE = "_changeMe"; private static OAuthContext expected; diff --git a/core/src/test/java/com/adobe/aio/workspace/WorkspaceTest.java b/core/src/test/java/com/adobe/aio/workspace/WorkspaceTest.java index 46a31c6b..d6b95085 100644 --- a/core/src/test/java/com/adobe/aio/workspace/WorkspaceTest.java +++ b/core/src/test/java/com/adobe/aio/workspace/WorkspaceTest.java @@ -18,7 +18,6 @@ import com.adobe.aio.auth.Context; import com.adobe.aio.auth.JwtContext; -import com.adobe.aio.auth.OAuthContext; import com.adobe.aio.util.Constants; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; diff --git a/core/src/test/resources/workspace.oauth.properties b/core/src/test/resources/workspace.oauth.properties deleted file mode 100644 index 1472e991..00000000 --- a/core/src/test/resources/workspace.oauth.properties +++ /dev/null @@ -1,33 +0,0 @@ -# -# Copyright 2017 Adobe. All rights reserved. -# This file is licensed to you under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. You may obtain a copy -# of the License at http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software distributed under -# the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS -# OF ANY KIND, either express or implied. See the License for the specific language -# governing permissions and limitations under the License. -# - -# aio_project_id = your Adobe Developer Console project id (project.id) -aio_project_id=aio_project_id_changeMe -# aio_consumer_org_id = your Adobe Developer Console consumer orgnaization id (project.org.id) -aio_consumer_org_id=aio_consumer_org_id_changeMe -# aio_ims_org_id = your Adobe Developer Console IMS Organization ID (project.org.ims_org_id) -aio_ims_org_id=aio_ims_org_id_changeMe -# aio_workspace_id = your Adobe Developer Console workspace Id (project.workspace.id) -aio_workspace_id=aio_workspace_id_changeMe -# aio_credential_id = your Adobe Developer Console jwt credential id (project.workspace.details.credentials[i].id) -aio_credential_id=aio_credential_id_changeMe -# aio_client_secret = your Adobe Developer Console jwt or OAuth credential client secret (project.workspace.details.credentials[i].jwt.client_secret) -aio_client_secret=aio_client_secret_changeMe -# aio_api_key = your Adobe Developer Console jwt credential API Key (or Client ID) (project.workspace.details.credentials[i].jwt.client_id -aio_api_key=aio_api_key_changeMe -# aio_technical_account_id = your Adobe Developer Console jwt credential technical account id (project.workspace.details.credentials[i].jwt.technical_account_id) -aio_technical_account_id=aio_technical_account_id_changeMe -# aio_oauth_scopes : comma separated list of scopes associated with your API, see your Adobe Developer Console OAuth credential scopes -# sample aio_meta_scopes: openid, AdobeID, read_organizations -aio_oauth_scopes=aio_oauth_scopes_changeMe - - diff --git a/core/src/test/resources/workspace.properties b/core/src/test/resources/workspace.properties index 0bfcbef8..8c22839c 100644 --- a/core/src/test/resources/workspace.properties +++ b/core/src/test/resources/workspace.properties @@ -29,6 +29,8 @@ aio_api_key=aio_api_key_changeMe aio_meta_scopes=aio_meta_scopes_changeMe # aio_technical_account_id = your Adobe Developer Console jwt credential technical account id (project.workspace.details.credentials[i].jwt.technical_account_id) aio_technical_account_id=aio_technical_account_id_changeMe - +# aio_oauth_scopes : comma separated list of scopes associated with your API, see your Adobe Developer Console OAuth credential scopes +# sample aio_meta_scopes: openid, AdobeID, read_organizations +aio_oauth_scopes=aio_oauth_scopes_changeMe From df503f32cfcbd4999543204790e46e370c97e9d4 Mon Sep 17 00:00:00 2001 From: hayatkha Date: Wed, 7 Aug 2024 18:06:04 +0530 Subject: [PATCH 6/7] Workspace Properties Reverted to original --- core/src/test/resources/workspace.properties | 1 + 1 file changed, 1 insertion(+) diff --git a/core/src/test/resources/workspace.properties b/core/src/test/resources/workspace.properties index 8c22839c..bd16d06d 100644 --- a/core/src/test/resources/workspace.properties +++ b/core/src/test/resources/workspace.properties @@ -29,6 +29,7 @@ aio_api_key=aio_api_key_changeMe aio_meta_scopes=aio_meta_scopes_changeMe # aio_technical_account_id = your Adobe Developer Console jwt credential technical account id (project.workspace.details.credentials[i].jwt.technical_account_id) aio_technical_account_id=aio_technical_account_id_changeMe + # aio_oauth_scopes : comma separated list of scopes associated with your API, see your Adobe Developer Console OAuth credential scopes # sample aio_meta_scopes: openid, AdobeID, read_organizations aio_oauth_scopes=aio_oauth_scopes_changeMe From a396f8c56b2d59c434ef91138a4456d4f5ab4891 Mon Sep 17 00:00:00 2001 From: hayatkha Date: Fri, 9 Aug 2024 11:31:40 +0530 Subject: [PATCH 7/7] Review Comments Incorporated --- core/src/main/java/com/adobe/aio/workspace/Workspace.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/com/adobe/aio/workspace/Workspace.java b/core/src/main/java/com/adobe/aio/workspace/Workspace.java index 743094f7..6411a607 100644 --- a/core/src/main/java/com/adobe/aio/workspace/Workspace.java +++ b/core/src/main/java/com/adobe/aio/workspace/Workspace.java @@ -272,9 +272,6 @@ public Builder addMetascope(final String metascope) { jwtbuilder = JwtContext.builder(); } jwtbuilder.addMetascope(metascope); - if(oAuthBuilder == null){ - oAuthBuilder = OAuthContext.builder(); - } return this; } @@ -295,10 +292,11 @@ public Builder configMap(final Map configMap) { .projectId(configMap.get(PROJECT_ID)) .workspaceId(configMap.get(WORKSPACE_ID)); // For backwards compatibility - should this be kept? - if(StringUtils.isBlank(configMap.get(OAuthContext.SCOPES))) { + if(StringUtils.isNotBlank(configMap.get(JwtContext.META_SCOPES))) { jwtbuilder = JwtContext.builder(); jwtbuilder.configMap(configMap); - } else { + } + if(StringUtils.isNotBlank(configMap.get(OAuthContext.SCOPES))) { oAuthBuilder = OAuthContext.builder(); oAuthBuilder.configMap(configMap); }