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/internal/WorkspaceSupplierImpl.java b/aem/core_aem/src/main/java/com/adobe/aio/aem/workspace/internal/WorkspaceSupplierImpl.java index aeaf2b93..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,6 +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(OAuthContext.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..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,10 +22,14 @@ 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 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", 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..6411a607 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; @@ -202,6 +203,7 @@ public static class Builder { private JwtContext.Builder jwtbuilder; private Context authContext; + private OAuthContext.Builder oAuthBuilder; private Builder() { } @@ -289,10 +291,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.isNotBlank(configMap.get(JwtContext.META_SCOPES))) { + jwtbuilder = JwtContext.builder(); + jwtbuilder.configMap(configMap); + } + if(StringUtils.isNotBlank(configMap.get(OAuthContext.SCOPES))) { + oAuthBuilder = OAuthContext.builder(); + oAuthBuilder.configMap(configMap); + } return this; } @@ -314,10 +321,13 @@ public Workspace build() { if (authContext != null) { return new Workspace(imsUrl, imsOrgId, apiKey, consumerOrgId, projectId, workspaceId, authContext); } - if (jwtbuilder == null) { - jwtbuilder = JwtContext.builder(); + 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()); + } else { + throw new IllegalStateException("Missing auth confiugration, set either jwt or oauth..."); } - 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..d6b95085 100644 --- a/core/src/test/java/com/adobe/aio/workspace/WorkspaceTest.java +++ b/core/src/test/java/com/adobe/aio/workspace/WorkspaceTest.java @@ -129,7 +129,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)