-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ODS-6448] Disable a key/secret without deleting it (#1170)
- Loading branch information
Showing
14 changed files
with
217 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
Artifacts/MsSql/Structure/Admin/0176-Update-CreateClientAccessToken.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
-- Licensed to the Ed-Fi Alliance under one or more agreements. | ||
-- The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
-- See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
CREATE OR ALTER PROCEDURE dbo.CreateClientAccessToken( | ||
@Id UNIQUEIDENTIFIER = NULL, | ||
@Expiration DATETIME = NULL, | ||
@Scope NVARCHAR(max) = NULL, | ||
@ApiClientId INT = NULL, | ||
@MaxTokenCount INT = NULL | ||
) | ||
AS | ||
BEGIN | ||
SET NOCOUNT ON | ||
|
||
DECLARE @ActiveTokenCount INT | ||
DECLARE @ClientIsApproved INT | ||
|
||
SET @ClientIsApproved = (SELECT COUNT(1) | ||
FROM dbo.ApiClients ac | ||
WHERE ac.ApiClientId = @ApiClientId | ||
AND ac.IsApproved = 1) | ||
|
||
IF (@ClientIsApproved = 0) | ||
BEGIN | ||
THROW 50000, 'Client is not approved', 1; | ||
END | ||
|
||
IF @MaxTokenCount < 1 | ||
SET @ActiveTokenCount = 0 | ||
ELSE | ||
BEGIN | ||
SET @ActiveTokenCount = (SELECT COUNT(1) | ||
FROM dbo.ClientAccessTokens actoken | ||
WHERE ApiClient_ApiClientId = @ApiClientId | ||
AND actoken.Expiration > GETUTCDATE()) | ||
END | ||
|
||
IF (@MaxTokenCount < 1) OR (@ActiveTokenCount < @MaxTokenCount) | ||
BEGIN | ||
INSERT INTO dbo.ClientAccessTokens(Id, Expiration, Scope, ApiClient_ApiClientId) | ||
VALUES (@Id, @Expiration, @Scope, @ApiClientId) | ||
END | ||
ELSE | ||
THROW 50000, 'Token limit reached', 1; | ||
END | ||
GO |
48 changes: 48 additions & 0 deletions
48
Artifacts/PgSql/Structure/Admin/0176-Update-CreateClientAccessToken.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
-- SPDX-License-Identifier: Apache-2.0 | ||
-- Licensed to the Ed-Fi Alliance under one or more agreements. | ||
-- The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0. | ||
-- See the LICENSE and NOTICES files in the project root for more information. | ||
|
||
CREATE OR REPLACE PROCEDURE dbo.CreateClientAccessToken( | ||
id uuid, | ||
expiration timestamp without time zone, | ||
scope text, | ||
apiclientid integer, | ||
maxtokencount integer) | ||
AS | ||
$BODY$ | ||
DECLARE | ||
active_token_count integer; | ||
client_is_approved integer; | ||
BEGIN | ||
|
||
SELECT count(1) | ||
INTO client_is_approved | ||
FROM dbo.apiclients ac | ||
WHERE ac.apiclientid = createclientaccesstoken.ApiClientId | ||
AND ac.isapproved = true; | ||
|
||
IF (client_is_approved = 0) THEN | ||
RAISE EXCEPTION USING MESSAGE = 'Client is not approved'; | ||
END IF; | ||
|
||
IF maxtokencount < 1 THEN | ||
active_token_count := 0; | ||
ELSE | ||
active_token_count := (SELECT COUNT(1) | ||
FROM dbo.clientaccesstokens actoken | ||
WHERE apiclient_apiclientid = ApiClientId | ||
AND actoken.expiration > current_timestamp at time zone 'utc'); | ||
END IF; | ||
|
||
IF (maxtokencount < 1) OR (active_token_count < maxtokencount) THEN | ||
INSERT INTO dbo.ClientAccessTokens(id, expiration, scope, apiclient_apiclientid) | ||
VALUES (CreateClientAccessToken.id, CreateClientAccessToken.expiration, CreateClientAccessToken.scope, | ||
apiclientid); | ||
ELSE | ||
RAISE EXCEPTION USING MESSAGE = 'Token limit reached'; | ||
END IF; | ||
|
||
END | ||
$BODY$ | ||
LANGUAGE plpgsql; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters