Skip to content

Commit 9fc2b7c

Browse files
committed
MPDO-1015: updated README file
1 parent de5f0c7 commit 9fc2b7c

File tree

1 file changed

+66
-43
lines changed

1 file changed

+66
-43
lines changed

‎samples/oci-apigw-idcs-auth-basic/README.md

+66-43
Original file line numberDiff line numberDiff line change
@@ -1,181 +1,204 @@
11
# API Gateway Basicauth function using IDCS
2-
This function provides verification of username and password against IDCS at runtime and allows only authorized users to access API gateway deployment.
2+
3+
This function provides verification of username and password against IDCS at runtime and allows only authorized users to access API gateway deployment.
34

45
The implementation conforms to the guidelines in the OCI Documentation at https://docs.cloud.oracle.com/en-us/iaas/Content/APIGateway/Tasks/apigatewayusingauthorizerfunction.htm.
56

67
As you make your way through this tutorial, look out for this icon ![user input icon](./images/userinput.png).
78
Whenever you see it, it's time for you to perform an action.
89

9-
1010
## Prerequisites
1111

1212
[Create users in IDCS](https://docs.oracle.com/en/cloud/paas/identity-cloud/uaids/create-user-accounts.html)
1313

1414
Before you deploy this sample function, make sure you have run step A, B and C of the [Oracle Functions Quick Start Guide for Cloud Shell](https://www.oracle.com/webfolder/technetwork/tutorials/infographics/oci_functions_cloudshell_quickview/functions_quickview_top/functions_quickview/index.html)
15-
* A - Set up your tenancy
16-
* B - Create application
17-
* C - Set up your Cloud Shell dev environment
15+
16+
- A - Set up your tenancy
17+
- B - Create application
18+
- C - Set up your Cloud Shell dev environment
1819

1920
## List Applications
21+
2022
Assuming your have successfully completed the prerequisites, you should see your
2123
application in the list of applications.
24+
2225
```
2326
fn ls apps
2427
```
2528

2629
## Deploy a function that implements an API
30+
2731
We need another function that will be a target for API Gateway. We suggest [oci-display-httprequest-info-python](../oci-display-httprequest-info-python).
28-
In Cloud Shell, run the *fn deploy* command to build the function and its dependencies as a Docker image,
32+
In Cloud Shell, run the _fn deploy_ command to build the function and its dependencies as a Docker image,
2933
push the image to OCIR, and deploy the function to Oracle Functions in your application.
3034

3135
![user input icon](./images/userinput.png)
36+
3237
```
3338
cd ../oci-display-httprequest-info-python
3439
fn -v deploy --app <app-name>
3540
```
3641

3742
## Create or Update your Dynamic Group for API Gateway
43+
3844
In order to invoke functions, your API Gateway must be part of a dynamic group.
3945

40-
When specifying the *Matching Rules*, we suggest matching all functions in a compartment with:
46+
When specifying the _Matching Rules_, we suggest matching all functions in a compartment with:
47+
4148
```
4249
ALL {resource.type = 'ApiGateway', resource.compartment.id = 'ocid1.compartment.oc1..aaaaaxxxxx'}
4350
```
4451

45-
4652
## Create or Update IAM Policies for API Gateway
53+
4754
Create a new policy that allows the API Gateway dynamic group to invoke functions. We will grant `use` access to `functions-family` in the compartment.
4855

4956
![user input icon](./images/userinput.png)
5057

5158
Your policy should look something like this:
59+
5260
```
5361
Allow dynamic-group <dynamic-group-name> to use functions-family in compartment <compartment-name>
5462
```
5563

5664
For more information on how to create policies, check the [documentation](https://docs.cloud.oracle.com/iaas/Content/Identity/Concepts/policysyntax.htm).
5765

58-
5966
## Configure Identity Cloud Service (IDCS)
67+
6068
Login to IDCS admin console and create, add an Application and select " Application".
6169
![IDCS-appcreate0](./images/IDCS-appcreate0.png)
6270

6371
Enter a name for your IDCS Application, for example "myAPI".
6472

6573
![IDCS-appcreate1](./images/IDCS-appcreate1.png)
6674

67-
For "Allowed Grant Types", select "Resource Owner". Click *Next*.
75+
For "Allowed Grant Types", select "Resource Owner". Click _Next_.
6876

6977
![IDCS-appcreate2](./images/IDCS-appcreate2.png)
7078

7179
For Primary Audience, enter anything "display-httprequest-info" for example.
72-
For Scopes, click *Add*. In the dialog box, for field "Scope", enter anything "display-httprequest-info" for example, click *Add*.
80+
For Scopes, click _Add_. In the dialog box, for field "Scope", enter anything "display-httprequest-info" for example, click _Add_.
7381

7482
![IDCS-appcreate3](./images/IDCS-appcreate3.png)
7583

76-
Click *Next*.
84+
Click _Next_.
7785

7886
![IDCS-appcreate4](./images/IDCS-appcreate4.png)
7987

80-
Click *Finish*.
88+
Click _Finish_.
8189

8290
![IDCS-appcreate5](./images/IDCS-appcreate5.png)
8391

84-
Now that the application is added, note the *Client ID* and *Client Secret*.
92+
Now that the application is added, note the _Client ID_ and _Client Secret_.
8593

8694
![IDCS-appcreate6](./images/IDCS-appcreate6.png)
8795

88-
Click *Close*.
96+
Click _Close_.
8997

90-
Click on Configurations tab under Client Information section click on add scope and select the *application name* from the dropdown. Note the scope value.
98+
Click on Configurations tab under Client Information section click on add scope and select the _application name_ from the dropdown. Note the scope value.
9199

92100
![IDCS-appcreate7](./images/IDCS-appcreate7.png)
93101
![IDCS-appcreate8](./images/IDCS-appcreate8.png)
94102

95-
Click *Activate* and click *Ok* in the dialog.
96-
97-
Note the *IDCS URL*, this is the URL you see in your browser URL bar, copy the IDCS url ( For example: https://idcs-xxxxxxxxxxx.identity.oraclecloud.com/ ), client-id, client-secret and scope these values are provided to the Basicauth function.
98-
103+
Click _Activate_ and click _Ok_ in the dialog.
99104

105+
Note the _IDCS URL_, this is the URL you see in your browser URL bar, copy the IDCS url ( For example: https://idcs-xxxxxxxxxxx.identity.oraclecloud.com/ ), client-id, client-secret and scope these values are provided to the Basicauth function.
100106

101107
## Review and customize the function
108+
102109
Review the following files in the current folder:
110+
103111
- [pom.xml](./pom.xml) specifies all the dependencies for your function
104112
- [func.yaml](./func.yaml) that contains metadata about your function and declares properties
105113
- [src/main/java/com/example/fn/BasicAuth.java](./src/main/java/com/example/fn/BasicAuth.java) which contains the Java code
106114

107-
The name of your function *basicauth* is specified in [func.yaml](./func.yaml).
115+
The name of your function _basicauth_ is specified in [func.yaml](./func.yaml).
116+
117+
set the following config variables to the values noted while configuring IDCS.
108118

109-
set the following variable in "src/main/java/com/example/utils/ResourceServerConfig.java" to the values noted while configuring IDCS.
110119
```
111-
public static final String CLIENT_ID = "xxxxxxxxxxx";
112-
public static final String CLIENT_SECRET = "xxxxxxxxx";
113-
public static final String IDCS_URL = "https://idcs-xxxxxxxx.identity.oraclecloud.com";
120+
CLIENT_ID = "xxxxxxxxxxx";
121+
CLIENT_SECRET = "xxxxxxxxx";
122+
IDCS_URL = "https://idcs-xxxxxxxx.identity.oraclecloud.com";
114123
115124
//INFORMATION ABOUT THE TARGET APPLICATION
116-
public static final String SCOPE_AUD = "display-httprequest-infodisplay-httprequest-info";
125+
SCOPE_AUD = "display-httprequest-infodisplay-httprequest-info";
117126
```
118127

128+
For the unit test to run, set the following variables in src/test/java/com/example/fn/BasicAuthTest.java
129+
130+
```
131+
private static final String TEST_IDCS_URL = "https://idcs-xxxxxxxx.identity.oraclecloud.com";
132+
private static final String TEST_CLIENT_ID = "xxxxxxxxxxx";
133+
private static final String TEST_CLIENT_SECRET = "xxxxxxxxxxx";
134+
private static final String TEST_SCOPE_AUD = "display-httprequest-infodisplay-httprequest-info";
135+
private static final String TEST_TOKEN = "xxxxxxxxxxx";
136+
```
119137

120138
## Deploy the basicauth function
121-
In Cloud Shell, run the *fn deploy* command to build the function and its dependencies as a Docker image,
139+
140+
In Cloud Shell, run the _fn deploy_ command to build the function and its dependencies as a Docker image,
122141
push the image to OCIR, and deploy the function to Oracle Functions in your application.
123142

124143
![user input icon](./images/userinput.png)
144+
125145
```
126146
fn -v deploy --app <app-name>
127147
```
148+
128149
## Invoke the basicauth function in cloud shell
129-
In Cloud Shell, run *fn invoke* command to invoke the deployed function, returns active status as true if the token is valid or else returns false.
150+
151+
In Cloud Shell, run _fn invoke_ command to invoke the deployed function, returns active status as true if the token is valid or else returns false.
130152

131153
![user input icon](./images/userinput.png)
154+
132155
```
133156
echo -n '{"type":"TOKEN", "token":"Basic aW5jaGFyYS5zaGFtYW5uYUBvcmFj....."}' | fn invoke <app-name> <func-name>
134157
```
135158

136159
## Create the API Gateway
160+
137161
The functions is meant to be invoked through API Gateway.
138162

139163
![user input icon](./images/userinput.png)
140164

141-
On the OCI console, navigate to *Developer Services* > *API Gateway*. Click on *Create Gateway*. Provide a name, set the type to "Public", select a compartment, a VCN, a public subnet, and click *Create*.
165+
On the OCI console, navigate to _Developer Services_ > _API Gateway_. Click on _Create Gateway_. Provide a name, set the type to "Public", select a compartment, a VCN, a public subnet, and click _Create_.
142166

143167
![APIGW create](./images/apigw-create.png)
144168

145-
Once created, click on your gateway. Under *Resources*, select *Deployments* and click *Create Deployment*.
169+
Once created, click on your gateway. Under _Resources_, select _Deployments_ and click _Create Deployment_.
146170

147-
* Provide a name, a path prefix ("/basicauth" for example).
148-
* Under *API Request Policies* Add Authentication
149-
* Authentication Type: *Custom*
150-
* Choose the application and the basicauth function
151-
* For "Authentication token", select *Header*
152-
* For the "Header Name", enter "Autorization"
171+
- Provide a name, a path prefix ("/basicauth" for example).
172+
- Under _API Request Policies_ Add Authentication
173+
- Authentication Type: _Custom_
174+
- Choose the application and the basicauth function
175+
- For "Authentication token", select _Header_
176+
- For the "Header Name", enter "Autorization"
153177

154-
Click *Save Changes* when you are finished
178+
Click _Save Changes_ when you are finished
155179
![APIGW deployment create](./images/apigw-deployment-create.png)
156180

157-
Click *Next*. Provide a name to the route ("/hello" for example), select methods eg: "GET", select *HTTP-URL* for your back-end.
181+
Click _Next_. Provide a name to the route ("/hello" for example), select methods eg: "GET", select _HTTP-URL_ for your back-end.
158182

159183
![APIGW deployment create](./images/apigw-deployment-create-route.png)
160184

161-
Click *Next* and finally, click *Save Changes*.
185+
Click _Next_ and finally, click _Save Changes_.
162186

163187
Note the endpoint of your API Gateway deployment.
164188

165189
![APIGW deployment endpoint](./images/apigw-deployment-endpoint.png)
166190

167-
168191
## Invoke the Deployment endpoint
192+
169193
The function validates if the user information is valid.
170194

171195
![user input icon](./images/userinput.png)
172196

173197
Use the curl command to make the HTTP request
198+
174199
```
175200
curl -i -u "<username>:<password>" https://d6xxxxxxxxk64.apigateway.us-ashburn-1.oci.customer-oci.com/basicauth/hello
176201
```
202+
177203
If the user is valid gateway will make a call to backend with HTTP200 else
178204
The gateway will reject the request with an HTTP401.
179-
180-
181-

0 commit comments

Comments
 (0)