Skip to content

Commit 4eecc04

Browse files
authored
Merge pull request #1429 from oracle-devrel/adding-iam-oic-token-exchange-script
adding-oic-token-exchange-demo
2 parents be88a5c + b478265 commit 4eecc04

24 files changed

+539
-3
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
environment.py
2+
saml.xml
3+
signedsaml.xml
4+
libs/__pycache__/*.*
5+
libs/__init__.py
6+
keys/*.pem
7+
keys/*.pub
8+
keys/*.crt
9+
*.pyc
10+
.venv/*.*
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Copyright (c) 2024 Oracle and/or its affiliates.
2+
3+
The Universal Permissive License (UPL), Version 1.0
4+
5+
Subject to the condition set forth below, permission is hereby granted to any
6+
person obtaining a copy of this software, associated documentation and/or data
7+
(collectively the "Software"), free of charge and under any and all copyright
8+
rights in the Software, and any and all patent rights owned or freely
9+
licensable by each licensor hereunder covering either (i) the unmodified
10+
Software as contributed to or provided by such licensor, or (ii) the Larger
11+
Works (as defined below), to deal in both
12+
13+
(a) the Software, and
14+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
15+
one is included with the Software (each a "Larger Work" to which the Software
16+
is contributed by such licensors),
17+
18+
without restriction, including without limitation the rights to copy, create
19+
derivative works of, display, perform, and distribute the Software and make,
20+
use, sell, offer for sale, import, export, have made, and have sold the
21+
Software and the Larger Work(s), and to sublicense the foregoing rights on
22+
either these or other terms.
23+
24+
This license is subject to the following condition:
25+
The above copyright notice and either this complete permission notice or at
26+
a minimum a reference to the UPL must be included in all copies or
27+
substantial portions of the Software.
28+
29+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
SOFTWARE.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import random
2+
import datetime
3+
import environment as env
4+
5+
#####Common Values#####
6+
idcs_token_endpoint_url = env.idcs_url + "/oauth2/v1/token"
7+
token_validity_in_seconds = 600
8+
content_type = {'Content-type': 'raw'}
9+
id = str(random.randint(10000,99999))
10+
idcs_audience = "https://identity.oraclecloud.com/"
11+
12+
#####Local SAML Request Values#####
13+
saml_grant_type = "urn:ietf:params:oauth:grant-type:saml2-bearer"
14+
15+
#####Local SAML Assertion Values#####
16+
xmlns = "urn:oasis:names:tc:SAML:2.0:assertion"
17+
version = "2.0"
18+
issuer = env.idcs_client_id
19+
nameIdFormat = "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress"
20+
subjectConfirmation = "urn:oasis:names:tc:SAML:2.0:cm:bearer"
21+
recipient = 'https://identity.oraclecloud.com/'
22+
authnContextClassRef = "urn:oasis:names:tc:SAML:2.0:ac:classes:X509"
23+
issueInstant = str(datetime.datetime.utcnow().isoformat() + 'Z')
24+
notOnOrAfter = str((datetime.datetime.utcnow()+datetime.timedelta(seconds=token_validity_in_seconds)).isoformat() + 'Z')
25+
26+
#####Local JWT Request Values#####
27+
jwt_grant_type = "urn:ietf:params:oauth:grant-type:jwt-bearer"
28+
29+
##### Local JWT Token Values######
30+
iat = datetime.datetime.utcnow()
31+
exp = datetime.datetime.utcnow()+datetime.timedelta(seconds=token_validity_in_seconds)
32+
algorithm = "RS256"
33+
header = {
34+
"typ": "JWT",
35+
"alg": algorithm,
36+
"kid": env.jwt_kid
37+
}
38+
jwt_input={
39+
"sub":env.userID,
40+
"aud": [
41+
idcs_audience
42+
],
43+
"iss": env.idcs_client_id,
44+
"prn": env.userID,
45+
"iat": iat,
46+
"exp": exp,
47+
"jti": id
48+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#VARIABLES TO CHANGE FOR YOUR ENVIRONMENT
2+
#########################################
3+
4+
#IDCS Instance Variables
5+
idcs_url = "" # e.g. "https://idcs-1234.identity.oraclecloud.com/"
6+
idcs_client_id="" # e.g. e123432ejcn43k2kdkrkfkke
7+
idcs_client_secret=""# e.g. e123432-ejcn-43k2-kdkr-kfdswe33kke
8+
9+
#Endpoint audience that you will be requesting an IDCS token for, e.g. "https://EAFE304003E34FA56.integration.ocp.oraclecloud.com:443"
10+
target_audience=""
11+
12+
#Scope of the target resource, e.g. "urn:opc:resource:consumer::all"
13+
idcs_scope=target_audience + ""
14+
15+
#Target Instance Variables
16+
#FQDN of the target host you will be calling with your IDCS token, e.g. "https://oic-fr2323hpc-fr.integration.ocp.oraclecloud.com"
17+
target_host=""
18+
19+
# URI of your target endpoint, e.g. "/ic/api/integration/v1/flows/rest/ECHO/1.0/Testing"
20+
target_url= target_host + ""
21+
22+
#Scope of your registered application which you will request in your IDCS token, e.g. "https://EAFE304003E34FA56.integration.ocp.oraclecloud.com:443urn:opc:resource:consumer::all"
23+
idcs_scope=""
24+
25+
26+
#User Variables
27+
#User ID to include in your locally generated token
28+
userID = ""
29+
30+
#JWT Variables
31+
#Value to set for your JWT KID
32+
jwt_kid = ""
33+
34+
#Local Variables (place keys/certs in keys folder and change filename below accordingly)
35+
private_key = "keys/local_private_key.pem"
36+
public_key = "keys/local_publickey.pub"
37+
public_cert = "keys/local_public_certificate.crt"
38+
39+
#OCI Secret Variables
40+
#OCID of the secret in which you have uploaded your private key in Vault (if using Vault integration)
41+
secret_id = ""
42+
43+
#Profile name for your OCI CLI (must be configured locally if using Vault integration)
44+
oci_profile = ""
118 KB
Loading
94.5 KB
Loading
106 KB
Loading
114 KB
Loading
129 KB
Loading
177 KB
Loading

0 commit comments

Comments
 (0)