Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/check-branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Comment PR
if: github.base_ref == 'master' && github.head_ref != 'next'
if: github.base_ref == 'master' && github.head_ref != 'staging'
uses: thollander/actions-comment-pull-request@v2
with:
message: |
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.
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.
- name: Check branch
if: github.base_ref == 'master' && github.head_ref != 'next'
if: github.base_ref == 'master' && github.head_ref != 'staging'
run: |
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."
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."
exit 1
5 changes: 4 additions & 1 deletion .github/workflows/sca-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Run Dotnet Restore
run: |
dotnet restore ./contentstack.model.generator/contentstack.model.generator.sln
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/dotnet@master
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --fail-on=all
args: --file=contentstack.model.generator/obj/project.assets.json
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### Version: 0.5.0
#### Date: Oct-05-2025

- Feat: Added OAuth Support in Dotnet Model Generator

### Version: 0.4.6
#### Date: Feb-19-2024

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright © 2012-2024 Contentstack. All Rights Reserved
Copyright © 2012-2025 Contentstack. All Rights Reserved

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
27 changes: 27 additions & 0 deletions OAuth.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## OAuth 2.0 Setup

### Prerequisites
1. **Contentstack Account**: You need a Contentstack account with appropriate permissions
2. **OAuth App**: Create an OAuth application in your Contentstack dashboard
3. **Redirect URI**: Configure a valid redirect URI (e.g., `http://localhost:8184`)

### OAuth Flow
1. **Authorization**: The tool displays the Contentstack OAuth authorization URL for you to open manually
2. **Authentication**: Open the URL in your browser, log in to your Contentstack account and authorize the application
3. **Callback**: You'll be redirected to your specified redirect URI with an authorization code
4. **Code Entry**: Copy the authorization code from the redirect URL and paste it into the tool
5. **Token Exchange**: The tool automatically exchanges the code for an access token
6. **Model Generation**: The tool fetches your content types and generates models
7. **Logout**: The tool automatically logs out and clears tokens

### Security Features
- **PKCE Support**: Uses Proof Key for Code Exchange for enhanced security
- **Client Secret Optional**: Supports both confidential and public clients
- **Automatic Token Management**: Handles token refresh and expiration
- **Secure Logout**: Automatically clears tokens after model generation

### Troubleshooting OAuth
- **Invalid Redirect URI**: Ensure the redirect URI matches exactly what's configured in your OAuth app
- **Client ID/Secret Issues**: Verify your OAuth app credentials
- **Network Issues**: Check your internet connection and Contentstack service status
- **Permission Issues**: Ensure your account has the necessary permissions for the stack
105 changes: 98 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ dotnet tool install -g contentstack.model.generator
## How to use
Once you install ```contentstack.model.generator``` run ```--help``` to view available commands.

### Authentication Methods

The Contentstack Model Generator supports two authentication methods:

1. **Traditional Authtoken Authentication** (default)
2. **OAuth 2.0 Authentication**

### Command Line Options

| Short key | Long Key | Description |
| -- | -- | -- |
| `-a` | `--api-key` | The Stack API key for the Content Management API |
| `-A` | `--authtoken` | The Authtoken for the Content Management API |
| `-A` | `--authtoken` | The Authtoken for the Content Management API (required for traditional auth) |
| `-b` | `--branch` | The branch header in the API request to fetch or manage modules located within specific branches. |
| `-e` | `--endpoint` | The Contentstack Host for the Content Management API |
| `-n` | `--namespace` | The namespace the classes should be created in |
Expand All @@ -25,33 +34,115 @@ Once you install ```contentstack.model.generator``` run ```--help``` to view av
| `-g` | `--group-prefix` | The Group Class Prefix. |
| `-p` | `--path` | Path to the file or directory to create files in. |

### Example 1
### OAuth 2.0 Options

| Long Key | Description |
| -- | -- |
| `--oauth` | Enable OAuth 2.0 authentication (mutually exclusive with traditional auth) |
| `--client-id` | OAuth Client ID (required for OAuth) (Default Value: Ie0FEfTzlfAHL4xM ) |
| `--client-secret` | OAuth Client Secret (optional for public clients using PKCE) |
| `--redirect-uri` | OAuth Redirect URI (required for OAuth) (Default Value: http://localhost:8184 ) |
| `--app-id` | OAuth App ID (optional) ( Default Value: 6400aa06db64de001a31c8a9 ) |
| `--scopes` | OAuth Scopes (optional, space-separated) |

## Examples

### Traditional API Key Authentication

#### Example 1: Basic Usage
To create classes in current directory run following command:
```
contentstack.model.generator -a <stack_api_key> -A <authtoken>
```

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

### Example 3
#### Example 3: With Namespace
To create classes with namespace run following command:
```
contentstack.model.generator -a <stack_api_key> -A <authtoken> -n YourProject.Models
```

### Example 4
To allow `Nullable` annotation context in model creation run following command
#### Example 4: With Nullable Annotations
To allow `Nullable` annotation context in model creation run following command:
```
contentstack.model.generator -a <stack_api_key> -A <authtoken> -N
```

### OAuth 2.0 Authentication

#### Example 5: OAuth with PKCE (Recommended)
For public clients or enhanced security, use OAuth with PKCE:
```
contentstack.model.generator --oauth -a <stack_api_key> --client-id <client_id> --redirect-uri http://localhost:8184
```

#### Example 6: OAuth with Client Secret
For confidential clients with client secret:
```
contentstack.model.generator --oauth -a <stack_api_key> --client-id <client_id> --client-secret <client_secret> --redirect-uri http://localhost:8184
```

#### Example 7: OAuth with App ID
For OAuth with specific app:
```
contentstack.model.generator --oauth -a <stack_api_key> --client-id <client_id> --redirect-uri http://localhost:8184 --app-id <app_id>
```

#### Example 8: OAuth with Custom Path and Namespace
```
contentstack.model.generator --oauth -a <stack_api_key> --client-id <client_id> --redirect-uri http://localhost:8184 -p /path/to/models -n YourProject.Models
```

## OAuth Command Example

Here's what you'll see when running an OAuth command:

```bash

$ contentstack.model.generator --oauth -a <api_key> --client-id myclient123 --redirect-uri http://localhost:8184

Contentstack Model Generator v0.5.0
=====================================

OAuth Authentication Required
=============================

Please open the following URL in your browser to authorize the application:

https://app.contentstack.com/#!/apps/6400aa06db64de001a31c8a9/authorize?response_type=code&client_id=myclient123&redirect_uri=http%3A%2F%2Flocalhost%3A8184&code_challenge=...

After authorization, you will be redirected to a local URL.
Please copy the 'code' parameter from the redirect URL and paste it here:

Authorization code: [User pastes the code here]

Exchanging authorization code for access token...
OAuth authentication successful!
Access token expires at: 2024-01-15 14:30:00 UTC

Fetching stack information...
Stack: My Contentstack Stack
API Key: api_key

Fetching content types...
Found 5 content types:
Generating files from content type

Files successfully created!
Opening <file_path>/Models

Logging out from OAuth...
OAuth logout successful!
```

### MIT License

Copyright (c) 2012-2024 Contentstack
Copyright (c) 2012-2025 Contentstack

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