Skip to content

Commit 04e7001

Browse files
authored
Merge pull request #9 from FastComments/api-keys
Fixing API Key Configuration For Pages, Subscriptions, SSO Users
2 parents 1fa8fc7 + 2e279b4 commit 04e7001

File tree

11 files changed

+246
-56
lines changed

11 files changed

+246
-56
lines changed

README.md

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,78 @@ to make working with the API easier, and the `pubsub` module which is a library
7979

8080
### Public vs Secured APIs
8181

82-
For the API client, there are two classes, `DefaultApi` and `PublicApi`. The `DefaultApi` contains methods that take your API key, and `PublicApi` contains api calls
83-
that can be made directly from a browser/mobile device/etc.
82+
For the API client, there are two classes, `DefaultApi` and `PublicApi`. The `DefaultApi` contains methods that require your API key, and `PublicApi` contains api calls
83+
that can be made directly from a browser/mobile device/etc without authentication.
84+
85+
## Quick Start
86+
87+
### Using Authenticated APIs (DefaultApi)
88+
89+
**Important:** You must set your API key on the ApiClient before making authenticated requests. If you don't, requests will fail with a 401 error.
90+
91+
```java
92+
import com.fastcomments.invoker.ApiClient;
93+
import com.fastcomments.invoker.ApiException;
94+
import com.fastcomments.api.DefaultApi;
95+
import com.fastcomments.model.*;
96+
97+
public class Example {
98+
public static void main(String[] args) {
99+
// Create and configure the API client
100+
ApiClient apiClient = new ApiClient();
101+
102+
// REQUIRED: Set your API key (get this from your FastComments dashboard)
103+
apiClient.setApiKey("YOUR_API_KEY_HERE");
104+
105+
// Create the API instance with the configured client
106+
DefaultApi api = new DefaultApi(apiClient);
107+
108+
// Now you can make authenticated API calls
109+
try {
110+
// Example: Add an SSO user
111+
CreateAPISSOUserData userData = new CreateAPISSOUserData();
112+
userData.setId("user-123");
113+
userData.setEmail("[email protected]");
114+
userData.setDisplayName("John Doe");
115+
116+
AddSSOUserAPIResponse response = api.addSSOUser("YOUR_TENANT_ID", userData)
117+
.execute();
118+
System.out.println("User created: " + response);
119+
120+
} catch (ApiException e) {
121+
System.err.println("Error: " + e.getResponseBody());
122+
// Common errors:
123+
// - 401: API key is missing or invalid
124+
// - 400: Request validation failed
125+
}
126+
}
127+
}
128+
```
129+
130+
### Using Public APIs (PublicApi)
131+
132+
Public endpoints don't require authentication:
133+
134+
```java
135+
import com.fastcomments.api.PublicApi;
136+
import com.fastcomments.invoker.ApiException;
137+
138+
PublicApi publicApi = new PublicApi();
139+
140+
try {
141+
var response = publicApi.getCommentsPublic("YOUR_TENANT_ID", "page-url-id")
142+
.execute();
143+
System.out.println(response);
144+
} catch (ApiException e) {
145+
e.printStackTrace();
146+
}
147+
```
148+
149+
### Common Issues
150+
151+
1. **401 "missing-api-key" error**: Make sure you call `apiClient.setApiKey("YOUR_KEY")` before creating the DefaultApi instance.
152+
2. **Wrong API class**: Use `DefaultApi` for server-side authenticated requests, `PublicApi` for client-side/public requests.
153+
3. **Null API key**: The SDK will silently skip authentication if the API key is null, leading to 401 errors.
84154

85155
## Notes
86156

client/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Add this dependency to your project's POM:
4040
<dependency>
4141
<groupId>com.fastcomments</groupId>
4242
<artifactId>client</artifactId>
43-
<version>0.0.25</version>
43+
<version>0.0.26</version>
4444
<scope>compile</scope>
4545
</dependency>
4646
```
@@ -56,7 +56,7 @@ Add this dependency to your project's build file:
5656
}
5757
5858
dependencies {
59-
implementation "com.fastcomments:client:0.0.25"
59+
implementation "com.fastcomments:client:0.0.26"
6060
}
6161
```
6262

@@ -70,7 +70,7 @@ mvn clean package
7070

7171
Then manually install the following JARs:
7272

73-
* `target/client-0.0.25.jar`
73+
* `target/client-0.0.26.jar`
7474
* `target/lib/*.jar`
7575

7676
## Getting Started

client/api/openapi.yaml

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,8 @@ paths:
19981998
schema:
19991999
$ref: '#/components/schemas/GetSubscriptionsAPIResponse'
20002000
description: Ok
2001-
security: []
2001+
security:
2002+
- api_key: []
20022003
x-accepts:
20032004
- application/json
20042005
post:
@@ -2024,7 +2025,8 @@ paths:
20242025
schema:
20252026
$ref: '#/components/schemas/CreateSubscriptionAPIResponse'
20262027
description: Ok
2027-
security: []
2028+
security:
2029+
- api_key: []
20282030
x-content-type: application/json
20292031
x-accepts:
20302032
- application/json
@@ -2060,7 +2062,8 @@ paths:
20602062
schema:
20612063
$ref: '#/components/schemas/DeleteSubscriptionAPIResponse'
20622064
description: Ok
2063-
security: []
2065+
security:
2066+
- api_key: []
20642067
x-accepts:
20652068
- application/json
20662069
/api/v1/sso-users:
@@ -2089,7 +2092,8 @@ paths:
20892092
schema:
20902093
$ref: '#/components/schemas/GetSSOUsers_200_response'
20912094
description: Ok
2092-
security: []
2095+
security:
2096+
- api_key: []
20932097
x-accepts:
20942098
- application/json
20952099
post:
@@ -2115,7 +2119,8 @@ paths:
21152119
schema:
21162120
$ref: '#/components/schemas/AddSSOUserAPIResponse'
21172121
description: Ok
2118-
security: []
2122+
security:
2123+
- api_key: []
21192124
x-content-type: application/json
21202125
x-accepts:
21212126
- application/json
@@ -2144,7 +2149,8 @@ paths:
21442149
schema:
21452150
$ref: '#/components/schemas/GetSSOUserByIdAPIResponse'
21462151
description: Ok
2147-
security: []
2152+
security:
2153+
- api_key: []
21482154
x-accepts:
21492155
- application/json
21502156
/api/v1/sso-users/by-email/{email}:
@@ -2172,7 +2178,8 @@ paths:
21722178
schema:
21732179
$ref: '#/components/schemas/GetSSOUserByEmailAPIResponse'
21742180
description: Ok
2175-
security: []
2181+
security:
2182+
- api_key: []
21762183
x-accepts:
21772184
- application/json
21782185
/api/v1/sso-users/{id}:
@@ -2214,7 +2221,8 @@ paths:
22142221
schema:
22152222
$ref: '#/components/schemas/DeleteSSOUserAPIResponse'
22162223
description: Ok
2217-
security: []
2224+
security:
2225+
- api_key: []
22182226
x-accepts:
22192227
- application/json
22202228
patch:
@@ -2254,7 +2262,8 @@ paths:
22542262
schema:
22552263
$ref: '#/components/schemas/PatchSSOUserAPIResponse'
22562264
description: Ok
2257-
security: []
2265+
security:
2266+
- api_key: []
22582267
x-content-type: application/json
22592268
x-accepts:
22602269
- application/json
@@ -2295,7 +2304,8 @@ paths:
22952304
schema:
22962305
$ref: '#/components/schemas/PutSSOUserAPIResponse'
22972306
description: Ok
2298-
security: []
2307+
security:
2308+
- api_key: []
22992309
x-content-type: application/json
23002310
x-accepts:
23012311
- application/json
@@ -2317,7 +2327,8 @@ paths:
23172327
schema:
23182328
$ref: '#/components/schemas/GetPagesAPIResponse'
23192329
description: Ok
2320-
security: []
2330+
security:
2331+
- api_key: []
23212332
x-accepts:
23222333
- application/json
23232334
post:
@@ -2343,7 +2354,8 @@ paths:
23432354
schema:
23442355
$ref: '#/components/schemas/AddPageAPIResponse'
23452356
description: Ok
2346-
security: []
2357+
security:
2358+
- api_key: []
23472359
x-content-type: application/json
23482360
x-accepts:
23492361
- application/json
@@ -2372,7 +2384,8 @@ paths:
23722384
schema:
23732385
$ref: '#/components/schemas/GetPageByURLIdAPIResponse'
23742386
description: Ok
2375-
security: []
2387+
security:
2388+
- api_key: []
23762389
x-accepts:
23772390
- application/json
23782391
/api/v1/pages/{id}:
@@ -2400,7 +2413,8 @@ paths:
24002413
schema:
24012414
$ref: '#/components/schemas/DeletePageAPIResponse'
24022415
description: Ok
2403-
security: []
2416+
security:
2417+
- api_key: []
24042418
x-accepts:
24052419
- application/json
24062420
patch:
@@ -2433,7 +2447,8 @@ paths:
24332447
schema:
24342448
$ref: '#/components/schemas/PatchPageAPIResponse'
24352449
description: Ok
2436-
security: []
2450+
security:
2451+
- api_key: []
24372452
x-content-type: application/json
24382453
x-accepts:
24392454
- application/json

client/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ apply plugin: 'java'
44
apply plugin: 'com.diffplug.spotless'
55

66
group = 'com.fastcomments'
7-
version = '0.0.25'
7+
version = '0.0.26'
88

99
buildscript {
1010
repositories {

client/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ lazy val root = (project in file(".")).
22
settings(
33
organization := "com.fastcomments",
44
name := "client",
5-
version := "0.0.25",
5+
version := "0.0.26",
66
scalaVersion := "2.11.4",
77
scalacOptions ++= Seq("-feature"),
88
javacOptions in compile ++= Seq("-Xlint:deprecation"),

0 commit comments

Comments
 (0)