Skip to content

Instantly share code, notes, and snippets.

@LindaLawton
Last active April 19, 2018 11:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LindaLawton/3ec0fb01170d4eeca486d616ca08f904 to your computer and use it in GitHub Desktop.
Save LindaLawton/3ec0fb01170d4eeca486d616ca08f904 to your computer and use it in GitHub Desktop.
Clones a Identtiy Server4 2.0 client. so that you can create a new one.
-- Instructions:
-- Run this in anohter window
-- SELECT CONVERT(varchar(255), NEWID());
-- Enter values for new client
DECLARE @clientIdGuid AS VARCHAR(100) = '386B5AA0-2045-43B5-8DFE-ECF474F0A3D6';
DECLARE @NEWCLIENTNAME AS VARCHAR(100) = 'Linda Test Client'
Declare @NEW_CLIENT_DESCRIPTION AS VARCHAR(100) = 'Linda Test CLient'
DECLARE @EMAIL_OF_OWNER AS VARCHAR(100) = 'xxxxx@EG.DK';
DECLARE @RedirectUri AS VARCHAR(100) = 'https://daimto.com';
DECLARE @PostLogoutRedirectUri AS VARCHAR(100) = 'https://daimto.com';
-- Standard VAlues
DECLARE @LOCATION AS VARCHAR(100) = 'test';
DECLARE @CLIENTID_TO_COPY AS VARCHAR(100) = '9a08c0d5-1779-44cc-ac09-606cae0776bb.apps.xena.biz';
Declare @CLONE_CLINET_ID AS INT;
SELECT @CLONE_CLINET_ID = ID FROM Clients WHERE CLIENTID = @CLIENTID_TO_COPY
DECLARE @NEW_GENREATED_CLIENT_ID VARCHAR(255) = @clientIdGuid + '.' + @LOCATION + '.apps.xena.biz';
DECLARE @NEW_CLIENT_ID AS INT;
SELECT @NEW_CLIENT_ID = ID FROM Clients WHERE ClientName = @NEWCLIENTNAME
Print @NEW_CLIENT_ID
IF @NEW_CLIENT_ID IS NULL
BEGIN
print 'hello'
insert into dbo.Clients
([AbsoluteRefreshTokenLifetime]
,[AccessTokenType]
,[AccessTokenLifetime]
,[AllowAccessTokensViaBrowser]
,[AllowOfflineAccess]
,[AllowPlainTextPkce]
,[AllowRememberConsent]
,[AlwaysIncludeUserClaimsInIdToken]
,[AlwaysSendClientClaims]
,[AuthorizationCodeLifetime]
,[ClientId]
,[ClientName]
,[ClientUri]
,[EnableLocalLogin]
,[Enabled]
,[IdentityTokenLifetime]
,[IncludeJwtId]
,[LogoUri]
,[BackChannelLogoutSessionRequired]
,[FrontChannelLogoutSessionRequired]
,[ProtocolType]
,[RefreshTokenExpiration]
,[RefreshTokenUsage]
,[RequireClientSecret]
,[RequireConsent]
,[RequirePkce]
,[SlidingRefreshTokenLifetime]
,[UpdateAccessTokenClaimsOnRefresh]
,[BackChannelLogoutUri]
,[ClientClaimsPrefix]
,[ConsentLifetime]
,[Description]
,[FrontChannelLogoutUri]
,[PairWiseSubjectSalt] )
select [AbsoluteRefreshTokenLifetime]
,[AccessTokenType]
,[AccessTokenLifetime]
,[AllowAccessTokensViaBrowser]
,[AllowOfflineAccess]
,[AllowPlainTextPkce]
,[AllowRememberConsent]
,[AlwaysIncludeUserClaimsInIdToken]
,[AlwaysSendClientClaims]
,[AuthorizationCodeLifetime]
,@NEW_GENREATED_CLIENT_ID
,@NEWCLIENTNAME
,[ClientUri]
,[EnableLocalLogin]
,[Enabled]
,[IdentityTokenLifetime]
,[IncludeJwtId]
,[LogoUri]
,[BackChannelLogoutSessionRequired]
,[FrontChannelLogoutSessionRequired]
,[ProtocolType]
,[RefreshTokenExpiration]
,[RefreshTokenUsage]
,[RequireClientSecret]
,[RequireConsent]
,[RequirePkce]
,[SlidingRefreshTokenLifetime]
,[UpdateAccessTokenClaimsOnRefresh]
,[BackChannelLogoutUri]
,[ClientClaimsPrefix]
,[ConsentLifetime]
,@NEW_CLIENT_DESCRIPTION
,[FrontChannelLogoutUri]
,[PairWiseSubjectSalt]
from dbo.Clients where clientid = @CLIENTID_TO_COPY
END
SELECT @NEW_CLIENT_ID = ID FROM Clients WHERE ClientName = @NEWCLIENTNAME
Print @NEW_CLIENT_ID
-- CLONE ClientClaims
INSERT INTO [Xena.Identity].[dbo].[ClientClaims]
([ClientId]
,[Type]
,[Value])
SELECT @NEW_CLIENT_ID
,[Type]
,[Value]
FROM [Xena.Identity].[dbo].[ClientClaims]
WHERE ClientId = @CLONE_CLINET_ID
and value not in (Select value from [Xena.Identity].[dbo].[ClientClaims] where clientid = @NEW_CLIENT_ID)
-- CLONE ClientCorsOrigins
INSERT INTO [Xena.Identity].[dbo].[ClientCorsOrigins]
([ClientId]
,[Origin])
SELECT
@NEW_CLIENT_ID
,[Origin]
FROM [Xena.Identity].[dbo].[ClientCorsOrigins]
where clientid = @CLONE_CLINET_ID
and origin not in (Select origin from [Xena.Identity].[dbo].[ClientCorsOrigins] where clientid = @NEW_CLIENT_ID AND [Origin] LIKE '%localhost%')
-- Clone [ClientGrantTypes]
INSERT INTO [Xena.Identity].[dbo].[ClientGrantTypes]
([ClientId]
,[GrantType])
SELECT
@NEW_CLIENT_ID
,[GrantType]
FROM [Xena.Identity].[dbo].[ClientGrantTypes]
where clientid =@CLONE_CLINET_ID
and GrantType not in (Select GrantType from [Xena.Identity].[dbo].[ClientGrantTypes] where clientid = @NEW_CLIENT_ID)
-- clone [ClientPostLogoutRedirectUris]
Insert into [Xena.Identity].[dbo].[ClientPostLogoutRedirectUris]
([ClientId]
,[PostLogoutRedirectUri])
SELECT
@NEW_CLIENT_ID
,[PostLogoutRedirectUri]
FROM [Xena.Identity].[dbo].[ClientPostLogoutRedirectUris]
where clientid =@CLONE_CLINET_ID
AND [PostLogoutRedirectUri] NOT IN (SELECT [PostLogoutRedirectUri]
FROM [Xena.Identity].[dbo].[ClientPostLogoutRedirectUris]
WHERE ClientId = @NEW_CLIENT_ID
AND [PostLogoutRedirectUri] LIKE '%localhost%')
-- clone [Xena.Identity].[dbo].[ClientRedirectUris]
insert into [Xena.Identity].[dbo].[ClientRedirectUris]
([ClientId]
,[RedirectUri])
SELECT @NEW_CLIENT_ID
,[RedirectUri]
FROM [Xena.Identity].[dbo].[ClientRedirectUris]
WHERE ClientId =@CLONE_CLINET_ID
AND [RedirectUri] NOT IN (SELECT [RedirectUri]
FROM [Xena.Identity].[dbo].[ClientRedirectUris]
WHERE ClientId = @NEW_CLIENT_ID
AND [RedirectUri] LIKE '%localhost%')
-- clone [Xena.Identity].[dbo].[[ClientScopes]]
insert into [Xena.Identity].[dbo].[ClientScopes]
([ClientId]
,[Scope])
SELECT @NEW_CLIENT_ID
,[Scope]
FROM [Xena.Identity].[dbo].[ClientScopes]
where clientid =@CLONE_CLINET_ID
and [Scope] not in (Select [Scope] from [Xena.Identity].[dbo].[ClientScopes] where clientid = @NEW_CLIENT_ID)
-- A values
INSERT INTO [Xena.Identity].[dbo].[ClientProperties] ([ClientId] ,[Key], [Value])
VALUES (@NEW_CLIENT_ID,'Created', getdate());
INSERT INTO [Xena.Identity].[dbo].[ClientProperties] ([ClientId] ,[Key], [Value])
VALUES (@NEW_CLIENT_ID,'Owner', @EMAIL_OF_OWNER);
INSERT INTO [dbo].[ClientPostLogoutRedirectUris] ([ClientId], [PostLogoutRedirectUri])
VALUES (@NEW_CLIENT_ID, @PostLogoutRedirectUri);
INSERT INTO [dbo].[ClientRedirectUris] ([ClientId], [RedirectUri])
VALUES (@NEW_CLIENT_ID, @RedirectUri + '/auth.html');
INSERT INTO [dbo].[ClientRedirectUris] ([ClientId], [RedirectUri])
VALUES (@NEW_CLIENT_ID, @RedirectUri + '/auth-silent.html');
INSERT INTO [dbo].[ClientCorsOrigins] ([ClientId], [Origin])
VALUES (@NEW_CLIENT_ID, @RedirectUri);
@LindaLawton
Copy link
Author

LindaLawton commented Mar 2, 2018

Note this does not create your client secret it just creates a new client based upon one you are cloning. In the case of a hybrid client secret isnt needed anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment