Skip to content

Commit fa04ab9

Browse files
authored
Merge pull request #251 from DecisionsDev/cognito-review-9501
Cognito review 9501
2 parents 28415f3 + 79ad849 commit fa04ab9

File tree

6 files changed

+22
-35
lines changed

6 files changed

+22
-35
lines changed

authentication/Cognito/README.md

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -244,31 +244,6 @@ The Client-credentials flow will be used for M2M (Machine to Machine) communicat
244244
It will enable communication between Decision Center and the Decision Server Console for ruleapp deployment.
245245
It will also enable the communication between Decision Center and Decision Runner for tests and simulation.
246246

247-
A Resource Server needs to be created to use the client-credentials flow and some custom scopes need to be configured. A scope is a level of access that an app can request to a resource.
248-
To get more details about scopes and resource server, you can read [OAuth 2.0 scopes and API authorization with resource servers](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-define-resource-servers.html?icmpid=docs_cognito_console_help_panel)
249-
250-
251-
1. Create a Resource Server
252-
253-
* Select the **odmuserpool** User Pool
254-
* Click **Domain** under *Branding* in the left-hand pane
255-
* Click the **Create resource server** button in the **Resource servers** pane
256-
* In **Resource server**:
257-
* Set *Resource server name* = **ODMClientCredentialsServer**
258-
* Set *Resource server identifier* = **odmcc**
259-
* In **Custom scopes**, create 2 scopes:
260-
* Click the **Add custom scope** button
261-
* Set *Scope name* = **read**
262-
* Set *Description* = **for GET requests**
263-
* Click the **Add another** button
264-
* Set *Scope name* = **write**
265-
* Set *Description* = **for POST requests**
266-
* Click the **create resource server** button
267-
268-
![Create Resource Server](images/CreateResourceServer.png)
269-
270-
2. Create a new client application
271-
272247
* Select the **odmuserpool** User Pool
273248
* Click **App clients** under *Application* in the left-hand pane
274249
* Click the **Create app client** button in the *App clients* pane
@@ -279,11 +254,12 @@ To get more details about scopes and resource server, you can read [OAuth 2.0 sc
279254
<!-- IS THE 'ALLOW_USER_SRP_AUTH' REALLY NECESSARY ?-->
280255
* Click the **Edit** button in the *App client information* pane
281256
* Enable the *Authentication flows* = **Sign in with secure remote password (SRP): ALLOW_USER_SRP_AUTH**
257+
* Click the **Save changes** button
282258

283259
* Click the **Login pages** tab and then the **Edit** button in the *Managed login pages configuration* pane
284260
* Keep *Identity providers* = **Cognito user pool**
285261
* Keep *OAuth 2.0 grant types* = **Client credentials**
286-
* Select *Custom scopes* = **odmcc/read** and **odmcc/write**
262+
* Take a note of the **default custom scope**
287263
* Click the **Save changes** button
288264

289265
![Client-Credentials App](images/ClientCredentialsApp.png)
@@ -317,7 +293,7 @@ Here are the details about the [Pre token generation Lambda trigger flow](https:
317293
We will use the pre token generation lambda trigger feature to the **identity** claim in in id_token by pushing the user email value.
318294

319295
Select the **odmuserpool** User Pool:
320-
* Select the **User pool properties** tab:
296+
* Click **Extensions** under *Authentication* in the left-hand pane
321297
* On the **Lambda triggers** section:
322298
* Click the **Add Lambda trigger** button
323299

@@ -461,6 +437,8 @@ In the **Container software library** tile, verify your entitlement on the **Vie
461437
If everything is well configured, the Cognito End-Points must be accessible at :
462438
https://cognito-idp.COGNITO_REGION.amazonaws.com/COGNITO_USER_POOL_ID/.well-known/openid-configuration <!-- markdown-link-check-disable-line -->
463439
440+
This URL can also be retrieved with the **Token signing key URL** displayed at the user pool overview replacing **jwk.json** by **openid-configuration**
441+
464442
Where:
465443
- *COGNITO_REGION* is the region where the COGNITO User Pool is deployed
466444
- *COGNITO_USER_POOL_ID* is the COGNITO User Pool ID retrieved at Amazon Cognito > User pools > odmuserpool > Overview > User pool ID
@@ -472,7 +450,7 @@ In the **Container software library** tile, verify your entitlement on the **Vie
472450
473451
Generate the files with the following command:
474452
```
475-
./generateTemplate.sh -u COGNITO_USER_POOL_ID -d COGNITO_DOMAIN_NAME_PREFIX -r COGNITO_REGION -i COGNITO_APP_CLIENT_ID -s COGNITO_APP_CLIENT_SECRET -c COGNITO_CC_CLIENT_ID -x COGNITO_CC_CLIENT_SECRET
453+
./generateTemplate.sh -u COGNITO_USER_POOL_ID -d COGNITO_DOMAIN_NAME_PREFIX -r COGNITO_REGION -i COGNITO_APP_CLIENT_ID -s COGNITO_APP_CLIENT_SECRET -c COGNITO_CC_CLIENT_ID -x COGNITO_CC_CLIENT_SECRET -p COGNITO_CC_DEFAULT_CUSTOM_SCOPE
476454
```
477455
478456
- *COGNITO_USER_POOL_ID* is the COGNITO User Pool ID retrieved at Amazon Cognito > User pools > odmuserpool > Overview > User pool ID
@@ -485,6 +463,7 @@ In the **Container software library** tile, verify your entitlement on the **Vie
485463
- *COGNITO_APP_CLIENT_SECRET* is the COGNITO ODM App Client Secret retrieved at Amazon Cognito > User pools > odmuserpool > App integration > odm > Client Secret
486464
- *COGNITO_CC_CLIENT_ID* is the COGNITO ODM Client-Credentials App Client ID retrieved at Amazon Cognito > User pools > odmuserpool > App integration > odmclientcredentials > Client ID
487465
- *COGNITO_CC_CLIENT_SECRET* is the COGNITO ODM Client-Credentials App Client Secret retrieved at Amazon Cognito > User pools > odmuserpool > App integration > odmclientcredentials > Client Secret
466+
- *COGNITO_CC_DEFAULT_CUSTOM_SCOPE* is the Client-Credentials App default custom scope that can be retrieved in the Login tab page
488467
489468
Here is an example of the command line:
490469
```
@@ -495,7 +474,8 @@ In the **Container software library** tile, verify your entitlement on the **Vie
495474
-i 7qo....................... \
496475
-s rrt................................................ \
497476
-c 6io....................... \
498-
-x c5b................................................
477+
-x c5b................................................ \
478+
-p default-m2m-resource-server-.... \
499479
```
500480
501481
The four files below are generated into a directory named `output` (generated by the script):
@@ -532,7 +512,7 @@ In the **Container software library** tile, verify your entitlement on the **Vie
532512
```shell
533513
helm search repo ibm-odm-prod
534514
NAME CHART VERSION APP VERSION DESCRIPTION
535-
ibm-helm/ibm-odm-prod 25.0.0 9.5.0.0 IBM Operational Decision Manager
515+
ibm-helm/ibm-odm-prod 25.1.0 9.5.0.1 IBM Operational Decision Manager
536516
```
537517

538518
### 3. Run the `helm install` command
@@ -689,9 +669,10 @@ export DS_RUNTIME_HOST=<HOSTNAME eg. k8s-default-odm2302o-ed3c5eee99-301488862.e
689669
export COGNITO_SERVER_URL=<URL eg. https://odm.auth.eu-west-3.amazoncognito.com>
690670
export CC_CLIENT_ID=<odmclientcredentials client ID>
691671
export CC_CLIENT_SECRET=<odmclientcredentials client secret>
672+
export CC_DEFAULT_CUSTOM_SCOPE=<odmclientcredentials default custom scope>
692673

693674
curl -k -X POST -H "Content-Type: application/x-www-form-urlencoded" \
694-
-d "client_id=$CC_CLIENT_ID&scope=odmcc/write&client_secret=$CC_CLIENT_SECRET&grant_type=client_credentials" \
675+
-d "client_id=$CC_CLIENT_ID&scope=$CC_DEFAULT_CUSTOM_SCOPE&client_secret=$CC_CLIENT_SECRET&grant_type=client_credentials" \
695676
"$COGNITO_SERVER_URL/oauth2/token" > response.json
696677

697678
export ACCESS_TOKEN=$(jq -r .access_token response.json)

authentication/Cognito/generateTemplate.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ Options:
3232
-s : Application Cient Secret
3333
-c : Client-Credentials Client ID
3434
-x : Client-Credentials Client Secret
35+
-p : Client-Credentials Default Custom Scope
3536
Usage example: $0 -i OdmClientId -s OdmClientSecret -r Region
3637
EOF
3738
}
3839

39-
while getopts "i:s:r:c:x:u:d:ha:" option; do
40+
while getopts "i:s:r:c:x:p:u:d:ha:" option; do
4041
case "${option}" in
4142
u) COGNITO_USER_POOL_ID=${OPTARG};;
4243
d) COGNITO_DOMAIN_NAME=${OPTARG};;
@@ -45,6 +46,7 @@ while getopts "i:s:r:c:x:u:d:ha:" option; do
4546
s) COGNITO_APP_CLIENT_SECRET=${OPTARG};;
4647
c) COGNITO_CC_CLIENT_ID=${OPTARG};;
4748
x) COGNITO_CC_CLIENT_SECRET=${OPTARG};;
49+
p) COGNITO_CC_DEFAULT_CUSTOM_SCOPE=${OPTARG};;
4850
h) usage; exit 0;;
4951
*) usage; exit 1;;
5052
esac
@@ -78,6 +80,10 @@ if [[ -z ${COGNITO_CC_CLIENT_SECRET} ]]; then
7880
echo "COGNITO_CC_CLIENT_SECRET has to be provided, either as in environment or with -x."
7981
exit 1
8082
fi
83+
if [[ -z ${COGNITO_CC_DEFAULT_CUSTOM_SCOPE} ]]; then
84+
echo "COGNITO_CC_DEFAULT_CUSTOM_SCOPE has to be provided, either as in environment or with -p."
85+
exit 1
86+
fi
8187

8288
mkdir -p $OUTPUT_DIR && cp $TEMPLATE_DIR/* $OUTPUT_DIR
8389
echo "Generating files for COGNITO"
@@ -88,4 +94,5 @@ sed -i.bak 's|COGNITO_APP_CLIENT_ID|'$COGNITO_APP_CLIENT_ID'|g' $OUTPUT_DIR/*
8894
sed -i.bak 's|COGNITO_APP_CLIENT_SECRET|'$COGNITO_APP_CLIENT_SECRET'|g' $OUTPUT_DIR/*
8995
sed -i.bak 's|COGNITO_CC_CLIENT_ID|'$COGNITO_CC_CLIENT_ID'|g' $OUTPUT_DIR/*
9096
sed -i.bak 's|COGNITO_CC_CLIENT_SECRET|'$COGNITO_CC_CLIENT_SECRET'|g' $OUTPUT_DIR/*
97+
sed -i.bak 's|COGNITO_CC_DEFAULT_CUSTOM_SCOPE|'$COGNITO_CC_DEFAULT_CUSTOM_SCOPE'|g' $OUTPUT_DIR/*
9198
rm -f $OUTPUT_DIR/*.bak
58.3 KB
Loading

authentication/Cognito/templates/OdmOidcProviders.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"logoutURL": "https://COGNITO_DOMAIN_NAME.auth.COGNITO_REGION.amazoncognito.com/oauth2/logout",
99
"clientId": "COGNITO_CC_CLIENT_ID",
1010
"clientSecret": "COGNITO_CC_CLIENT_SECRET",
11-
"scope": "odmcc/write"
11+
"scope": "COGNITO_CC_DEFAULT_CUSTOM_SCOPE"
1212
}
1313
]
1414
}

authentication/Cognito/templates/OdmOidcProvidersRD.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"name": "cognito-for-rd",
55
"authorizationURL": "https://COGNITO_DOMAIN_NAME.auth.COGNITO_REGION.amazoncognito.com/oauth2/authorize",
66
"tokenURL": "https://COGNITO_DOMAIN_NAME.auth.COGNITO_REGION.amazoncognito.com/oauth2/token",
7-
"logoutURL": "https://COGNITO_DOMAIN_NAME.auth.COGNITO_REGION.amazoncognito.com/oauth2/logout",
87
"clientId": "COGNITO_APP_CLIENT_ID",
98
"clientSecret": "COGNITO_APP_CLIENT_SECRET",
109
"callbackPort": "9081",

authentication/Cognito/templates/openIdParameters.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ OPENID_ALLOWED_DOMAINS=COGNITO_DOMAIN_NAME.auth.COGNITO_REGION.amazoncognito.com
33
OPENID_PROVIDER=cognito-cc
44
OPENID_CLIENT_ID=COGNITO_APP_CLIENT_ID
55
OPENID_CLIENT_SECRET=COGNITO_APP_CLIENT_SECRET
6-
OPENID_AUTHORIZATION_URL=https://COGNITO_DOMAIN_NAME.auth.COGNITO_REGION.amazoncognito.com/oauth2//auth
6+
OPENID_AUTHORIZATION_URL=https://COGNITO_DOMAIN_NAME.auth.COGNITO_REGION.amazoncognito.com/oauth2/auth
77
OPENID_TOKEN_URL=https://COGNITO_DOMAIN_NAME.auth.COGNITO_REGION.amazoncognito.com/oauth2/token

0 commit comments

Comments
 (0)