Skip to content

Commit 367c9ea

Browse files
Merge pull request #28 from contentstack/staging
DX | 06-10-2025 | Release
2 parents 82b4b67 + 778f32e commit 367c9ea

27 files changed

Lines changed: 3956 additions & 208 deletions

.github/workflows/check-branch.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ jobs:
88
runs-on: ubuntu-latest
99
steps:
1010
- name: Comment PR
11-
if: github.base_ref == 'master' && github.head_ref != 'next'
11+
if: github.base_ref == 'master' && github.head_ref != 'staging'
1212
uses: thollander/actions-comment-pull-request@v2
1313
with:
1414
message: |
15-
We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch.
15+
We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the staging branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch.
1616
- name: Check branch
17-
if: github.base_ref == 'master' && github.head_ref != 'next'
17+
if: github.base_ref == 'master' && github.head_ref != 'staging'
1818
run: |
19-
echo "ERROR: We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the next branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch."
19+
echo "ERROR: We regret to inform you that you are currently not able to merge your changes into the master branch due to restrictions applied by our SRE team. To proceed with merging your changes, we kindly request that you create a pull request from the staging branch. Our team will then review the changes and work with you to ensure a successful merge into the master branch."
2020
exit 1

.github/workflows/sca-scan.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ jobs:
77
runs-on: ubuntu-latest
88
steps:
99
- uses: actions/checkout@master
10+
- name: Run Dotnet Restore
11+
run: |
12+
dotnet restore ./contentstack.model.generator/contentstack.model.generator.sln
1013
- name: Run Snyk to check for vulnerabilities
1114
uses: snyk/actions/dotnet@master
1215
env:
1316
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
1417
with:
15-
args: --fail-on=all
18+
args: --file=contentstack.model.generator/obj/project.assets.json

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### Version: 0.5.0
2+
#### Date: Oct-05-2025
3+
4+
- Feat: Added OAuth Support in Dotnet Model Generator
5+
16
### Version: 0.4.6
27
#### Date: Feb-19-2024
38

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright © 2012-2024 Contentstack. All Rights Reserved
3+
Copyright © 2012-2025 Contentstack. All Rights Reserved
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

OAuth.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## OAuth 2.0 Setup
2+
3+
### Prerequisites
4+
1. **Contentstack Account**: You need a Contentstack account with appropriate permissions
5+
2. **OAuth App**: Create an OAuth application in your Contentstack dashboard
6+
3. **Redirect URI**: Configure a valid redirect URI (e.g., `http://localhost:8184`)
7+
8+
### OAuth Flow
9+
1. **Authorization**: The tool displays the Contentstack OAuth authorization URL for you to open manually
10+
2. **Authentication**: Open the URL in your browser, log in to your Contentstack account and authorize the application
11+
3. **Callback**: You'll be redirected to your specified redirect URI with an authorization code
12+
4. **Code Entry**: Copy the authorization code from the redirect URL and paste it into the tool
13+
5. **Token Exchange**: The tool automatically exchanges the code for an access token
14+
6. **Model Generation**: The tool fetches your content types and generates models
15+
7. **Logout**: The tool automatically logs out and clears tokens
16+
17+
### Security Features
18+
- **PKCE Support**: Uses Proof Key for Code Exchange for enhanced security
19+
- **Client Secret Optional**: Supports both confidential and public clients
20+
- **Automatic Token Management**: Handles token refresh and expiration
21+
- **Secure Logout**: Automatically clears tokens after model generation
22+
23+
### Troubleshooting OAuth
24+
- **Invalid Redirect URI**: Ensure the redirect URI matches exactly what's configured in your OAuth app
25+
- **Client ID/Secret Issues**: Verify your OAuth app credentials
26+
- **Network Issues**: Check your internet connection and Contentstack service status
27+
- **Permission Issues**: Ensure your account has the necessary permissions for the stack

README.md

Lines changed: 98 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,19 @@ dotnet tool install -g contentstack.model.generator
1212
## How to use
1313
Once you install ```contentstack.model.generator``` run ```--help``` to view available commands.
1414

15+
### Authentication Methods
16+
17+
The Contentstack Model Generator supports two authentication methods:
18+
19+
1. **Traditional Authtoken Authentication** (default)
20+
2. **OAuth 2.0 Authentication**
21+
22+
### Command Line Options
23+
1524
| Short key | Long Key | Description |
1625
| -- | -- | -- |
1726
| `-a` | `--api-key` | The Stack API key for the Content Management API |
18-
| `-A` | `--authtoken` | The Authtoken for the Content Management API |
27+
| `-A` | `--authtoken` | The Authtoken for the Content Management API (required for traditional auth) |
1928
| `-b` | `--branch` | The branch header in the API request to fetch or manage modules located within specific branches. |
2029
| `-e` | `--endpoint` | The Contentstack Host for the Content Management API |
2130
| `-n` | `--namespace` | The namespace the classes should be created in |
@@ -25,33 +34,115 @@ Once you install ```contentstack.model.generator``` run ```--help``` to view av
2534
| `-g` | `--group-prefix` | The Group Class Prefix. |
2635
| `-p` | `--path` | Path to the file or directory to create files in. |
2736

28-
### Example 1
37+
### OAuth 2.0 Options
38+
39+
| Long Key | Description |
40+
| -- | -- |
41+
| `--oauth` | Enable OAuth 2.0 authentication (mutually exclusive with traditional auth) |
42+
| `--client-id` | OAuth Client ID (required for OAuth) (Default Value: Ie0FEfTzlfAHL4xM ) |
43+
| `--client-secret` | OAuth Client Secret (optional for public clients using PKCE) |
44+
| `--redirect-uri` | OAuth Redirect URI (required for OAuth) (Default Value: http://localhost:8184 ) |
45+
| `--app-id` | OAuth App ID (optional) ( Default Value: 6400aa06db64de001a31c8a9 ) |
46+
| `--scopes` | OAuth Scopes (optional, space-separated) |
47+
48+
## Examples
49+
50+
### Traditional API Key Authentication
51+
52+
#### Example 1: Basic Usage
2953
To create classes in current directory run following command:
3054
```
3155
contentstack.model.generator -a <stack_api_key> -A <authtoken>
3256
```
3357

34-
### Example 2
58+
#### Example 2: Specific Path
3559
To create classes in specific path run following command:
3660
```
3761
contentstack.model.generator -a <stack_api_key> -A <authtoken> -p /User/xxx/Desktop
3862
```
3963

40-
### Example 3
64+
#### Example 3: With Namespace
4165
To create classes with namespace run following command:
4266
```
4367
contentstack.model.generator -a <stack_api_key> -A <authtoken> -n YourProject.Models
4468
```
4569

46-
### Example 4
47-
To allow `Nullable` annotation context in model creation run following command
70+
#### Example 4: With Nullable Annotations
71+
To allow `Nullable` annotation context in model creation run following command:
4872
```
4973
contentstack.model.generator -a <stack_api_key> -A <authtoken> -N
5074
```
5175

76+
### OAuth 2.0 Authentication
77+
78+
#### Example 5: OAuth with PKCE (Recommended)
79+
For public clients or enhanced security, use OAuth with PKCE:
80+
```
81+
contentstack.model.generator --oauth -a <stack_api_key> --client-id <client_id> --redirect-uri http://localhost:8184
82+
```
83+
84+
#### Example 6: OAuth with Client Secret
85+
For confidential clients with client secret:
86+
```
87+
contentstack.model.generator --oauth -a <stack_api_key> --client-id <client_id> --client-secret <client_secret> --redirect-uri http://localhost:8184
88+
```
89+
90+
#### Example 7: OAuth with App ID
91+
For OAuth with specific app:
92+
```
93+
contentstack.model.generator --oauth -a <stack_api_key> --client-id <client_id> --redirect-uri http://localhost:8184 --app-id <app_id>
94+
```
95+
96+
#### Example 8: OAuth with Custom Path and Namespace
97+
```
98+
contentstack.model.generator --oauth -a <stack_api_key> --client-id <client_id> --redirect-uri http://localhost:8184 -p /path/to/models -n YourProject.Models
99+
```
100+
101+
## OAuth Command Example
102+
103+
Here's what you'll see when running an OAuth command:
104+
105+
```bash
106+
107+
$ contentstack.model.generator --oauth -a <api_key> --client-id myclient123 --redirect-uri http://localhost:8184
108+
109+
Contentstack Model Generator v0.5.0
110+
=====================================
111+
112+
OAuth Authentication Required
113+
=============================
114+
115+
Please open the following URL in your browser to authorize the application:
116+
117+
https://app.contentstack.com/#!/apps/6400aa06db64de001a31c8a9/authorize?response_type=code&client_id=myclient123&redirect_uri=http%3A%2F%2Flocalhost%3A8184&code_challenge=...
118+
119+
After authorization, you will be redirected to a local URL.
120+
Please copy the 'code' parameter from the redirect URL and paste it here:
121+
122+
Authorization code: [User pastes the code here]
123+
124+
Exchanging authorization code for access token...
125+
OAuth authentication successful!
126+
Access token expires at: 2024-01-15 14:30:00 UTC
127+
128+
Fetching stack information...
129+
Stack: My Contentstack Stack
130+
API Key: api_key
131+
132+
Fetching content types...
133+
Found 5 content types:
134+
Generating files from content type
135+
136+
Files successfully created!
137+
Opening <file_path>/Models
138+
139+
Logging out from OAuth...
140+
OAuth logout successful!
141+
```
142+
52143
### MIT License
53144

54-
Copyright (c) 2012-2024 Contentstack
145+
Copyright (c) 2012-2025 Contentstack
55146

56147
Permission is hereby granted, free of charge, to any person obtaining a copy
57148
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)