Skip to content

Commit 05ddfbd

Browse files
committed
squash degroff/finish-api-keys into master
1 parent c476d5f commit 05ddfbd

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

src/FusionAuthClient.ts

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,26 @@ export class FusionAuthClient {
164164
.go();
165165
}
166166

167+
/**
168+
* Creates an API key. You can optionally specify a unique Id for the key, if not provided one will be generated.
169+
* an API key can only be created with equal or lesser authority. An API key cannot create another API key unless it is granted
170+
* to that API key.
171+
*
172+
* If an API key is locked to a tenant, it can only create API Keys for that same tenant.
173+
*
174+
* @param {UUID} keyId (Optional) The unique Id of the API key. If not provided a secure random Id will be generated.
175+
* @param {APIKeyRequest} request The request object that contains all of the information needed to create the APIKey.
176+
* @returns {Promise<ClientResponse<APIKeyResponse>>}
177+
*/
178+
createAPIKey(keyId: UUID, request: APIKeyRequest): Promise<ClientResponse<APIKeyResponse>> {
179+
return this.start<APIKeyResponse, Errors>()
180+
.withUri('/api/api-key')
181+
.withUriSegment(keyId)
182+
.withJSONBody(request)
183+
.withMethod("POST")
184+
.go();
185+
}
186+
167187
/**
168188
* Creates an application. You can optionally specify an Id for the application, if not provided one will be generated.
169189
*
@@ -661,6 +681,20 @@ export class FusionAuthClient {
661681
.go();
662682
}
663683

684+
/**
685+
* Deletes the API key for the given Id.
686+
*
687+
* @param {UUID} keyId The Id of the authentication API key to delete.
688+
* @returns {Promise<ClientResponse<void>>}
689+
*/
690+
deleteAPIKey(keyId: UUID): Promise<ClientResponse<void>> {
691+
return this.start<void, Errors>()
692+
.withUri('/api/api-key')
693+
.withUriSegment(keyId)
694+
.withMethod("DELETE")
695+
.go();
696+
}
697+
664698
/**
665699
* Hard deletes an application. This is a dangerous operation and should not be used in most circumstances. This will
666700
* delete the application, any registrations for that application, metrics and reports for the application, all the
@@ -1575,6 +1609,22 @@ export class FusionAuthClient {
15751609
.go();
15761610
}
15771611

1612+
/**
1613+
* Updates an authentication API key by given id
1614+
*
1615+
* @param {UUID} keyId The Id of the authentication key. If not provided a secure random api key will be generated.
1616+
* @param {APIKeyRequest} request The request object that contains all of the information needed to create the APIKey.
1617+
* @returns {Promise<ClientResponse<APIKeyResponse>>}
1618+
*/
1619+
patchAPIKey(keyId: UUID, request: APIKeyRequest): Promise<ClientResponse<APIKeyResponse>> {
1620+
return this.start<APIKeyResponse, Errors>()
1621+
.withUri('/api/api-key')
1622+
.withUriSegment(keyId)
1623+
.withJSONBody(request)
1624+
.withMethod("POST")
1625+
.go();
1626+
}
1627+
15781628
/**
15791629
* Updates, via PATCH, the application with the given Id.
15801630
*
@@ -2078,6 +2128,20 @@ export class FusionAuthClient {
20782128
.go();
20792129
}
20802130

2131+
/**
2132+
* Retrieves an authentication API key for the given id
2133+
*
2134+
* @param {UUID} keyId The Id of the API key to retrieve.
2135+
* @returns {Promise<ClientResponse<APIKeyResponse>>}
2136+
*/
2137+
retrieveAPIKey(keyId: UUID): Promise<ClientResponse<APIKeyResponse>> {
2138+
return this.start<APIKeyResponse, Errors>()
2139+
.withUri('/api/api-key')
2140+
.withUriSegment(keyId)
2141+
.withMethod("GET")
2142+
.go();
2143+
}
2144+
20812145
/**
20822146
* Retrieves a single action log (the log of a user action that was taken on a user previously) for the given Id.
20832147
*
@@ -3796,6 +3860,22 @@ export class FusionAuthClient {
37963860
.go();
37973861
}
37983862

3863+
/**
3864+
* Updates an API key by given id
3865+
*
3866+
* @param {UUID} apiKeyId The Id of the API key to update.
3867+
* @param {APIKeyRequest} request The request object that contains all of the information used to create the API Key.
3868+
* @returns {Promise<ClientResponse<APIKeyResponse>>}
3869+
*/
3870+
updateAPIKey(apiKeyId: UUID, request: APIKeyRequest): Promise<ClientResponse<APIKeyResponse>> {
3871+
return this.start<APIKeyResponse, Errors>()
3872+
.withUri('/api/api-key')
3873+
.withUriSegment(apiKeyId)
3874+
.withJSONBody(request)
3875+
.withMethod("PUT")
3876+
.go();
3877+
}
3878+
37993879
/**
38003880
* Updates the application with the given Id.
38013881
*
@@ -4398,6 +4478,49 @@ export enum Algorithm {
43984478
none = "none"
43994479
}
44004480

4481+
/**
4482+
* domain POJO to represent AuthenticationKey
4483+
*
4484+
* @author sanjay
4485+
*/
4486+
export interface APIKey {
4487+
id?: UUID;
4488+
insertInstant?: number;
4489+
key?: string;
4490+
keyManager?: boolean;
4491+
lastUpdateInstant?: number;
4492+
metaData?: APIKeyMetaData;
4493+
permissions?: APIKeyPermissions;
4494+
tenantId?: UUID;
4495+
}
4496+
4497+
export interface APIKeyMetaData {
4498+
attributes?: Record<string, string>;
4499+
}
4500+
4501+
export interface APIKeyPermissions {
4502+
endpoints?: Record<string, Array<string>>;
4503+
}
4504+
4505+
/**
4506+
* Authentication key request object.
4507+
*
4508+
* @author Sanjay
4509+
*/
4510+
export interface APIKeyRequest {
4511+
apiKey?: APIKey;
4512+
sourceKeyId?: UUID;
4513+
}
4514+
4515+
/**
4516+
* Authentication key response object.
4517+
*
4518+
* @author Sanjay
4519+
*/
4520+
export interface APIKeyResponse {
4521+
apiKey?: APIKey;
4522+
}
4523+
44014524
/**
44024525
* @author Daniel DeGroff
44034526
*/

0 commit comments

Comments
 (0)