-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: changed the structure of the module to be more like the ssi-cor…
…e module of ours. Plus, changed some documents
- Loading branch information
Showing
23 changed files
with
182 additions
and
403 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Change Log | ||
|
||
All notable changes to this project will be documented in this file. | ||
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. |
File renamed without changes.
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
24 changes: 24 additions & 0 deletions
24
packages/ms-authenticator/__tests__/authenticators.test.ts
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,24 @@ | ||
import {ClientCredentialAuthenticator, UsernamePasswordAuthenticator} from "../src/authenticators"; | ||
|
||
describe('@sphereon/ms-authenticator', ()=>{ | ||
|
||
it('should authenticate using clientCredential', async () => { | ||
|
||
return await expect(ClientCredentialAuthenticator({ | ||
azClientId: '04c2bd60-cdbf-4935-80dd-110fdf473e6e', | ||
azClientSecret:'<YOUR_CCLIENT_SECRET>', | ||
azTenantId: 'e2a42b2f-7460-4499-afc2-425315ef058a', | ||
credentialManifest:'https://beta.eu.did.msidentity.com/v1.0/e2a42b2f-7460-4499-afc2-425315ef058a/verifiableCredential/contracts/VerifiedCredentialExpert2' | ||
})).resolves.not.toBeNull(); | ||
}); | ||
|
||
it('should authenticate using usernamePassword', async () => { | ||
return await expect(UsernamePasswordAuthenticator({ | ||
azTenantId: 'e2a42b2f-7460-4499-afc2-425315ef058a', | ||
azClientId: '04c2bd60-cdbf-4935-80dd-110fdf473e6e', | ||
scopes: ["user.read"], | ||
username: '<YOUR_USERNAME>', | ||
password:'<YOUR_PASSWORD>', | ||
})).resolves.not.toBeNull(); | ||
}); | ||
}) |
File renamed without changes.
12 changes: 3 additions & 9 deletions
12
packages/ms-vc-api-issuer/package.json → packages/ms-authenticator/package.json
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
126 changes: 126 additions & 0 deletions
126
packages/ms-authenticator/src/authenticators/MsAuthenticator.ts
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,126 @@ | ||
import { ConfidentialClientApplication, LogLevel, PublicClientApplication, UsernamePasswordRequest } from '@azure/msal-node' | ||
import { | ||
IMsAuthenticationAuthorizationCodeArgs, | ||
IMsAuthenticationClientCredentialArgs, | ||
IMsAuthenticationOnBehalfOfArgs, IMsAuthenticationSilentFlowArgs, | ||
IMsAuthenticationUsernamePasswordArgs, | ||
} from '../index' | ||
|
||
import { fetch } from 'cross-fetch' | ||
|
||
/** | ||
* Not implemented yet | ||
* @param authenticationArgs | ||
* @constructor | ||
*/ | ||
export async function AuthorizationCodeAuthenticator(authenticationArgs: IMsAuthenticationAuthorizationCodeArgs): Promise<string> { | ||
throw new Error("This authentication method is not implemented yet.") | ||
} | ||
|
||
/** | ||
* Not implemented yet | ||
* @param authenticationArgs | ||
* @constructor | ||
*/ | ||
export async function BehalfOfAuthenticator(authenticationArgs: IMsAuthenticationOnBehalfOfArgs): Promise<string> { | ||
throw new Error("This authentication method is not implemented yet.") | ||
} | ||
|
||
/** | ||
* necessary fields are: | ||
* azClientId: clientId of the application you're trying to login | ||
* azClientSecret: secret of the application you're trying to login | ||
* azTenantId: your MS Azure tenantId | ||
* credentialManifest: address of your credential manifest. usually in following format: | ||
* https://beta.eu.did.msidentity.com/v1.0/<tenant_id>/verifiableCredential/contracts/<verifiable_credential_schema> | ||
* @param authenticationArgs | ||
* @constructor | ||
*/ | ||
export async function ClientCredentialAuthenticator(authenticationArgs: IMsAuthenticationClientCredentialArgs): Promise<string> { | ||
var msalConfig = { | ||
auth: { | ||
clientId: authenticationArgs.azClientId, | ||
authority: 'https://login.microsoftonline.com/' + authenticationArgs.azTenantId, | ||
clientSecret: authenticationArgs.azClientSecret, | ||
}, | ||
system: { | ||
loggerOptions: { | ||
piiLoggingEnabled: false, | ||
logLevel: LogLevel.Verbose, | ||
} | ||
} | ||
} | ||
|
||
const cca = new ConfidentialClientApplication(msalConfig) | ||
const msalClientCredentialRequest = { | ||
scopes: ['3db474b9-6a0c-4840-96ac-1fceb342124f/.default'], | ||
skipCache: false, | ||
} | ||
await fetch('https://login.microsoftonline.com/' + authenticationArgs.azTenantId + '/v2.0/.well-known/openid-configuration', {method: 'GET'}) | ||
.then((res) => res.json()) | ||
.then(async (resp) => { | ||
console.log(`tenant_region_scope = ${resp.tenant_region_scope}`) | ||
let msIdentityHostName = 'https://beta.did.msidentity.com/v1.0/' | ||
if (resp.tenant_region_scope == 'EU') { | ||
msIdentityHostName = 'https://beta.eu.did.msidentity.com/v1.0/' | ||
} | ||
// Check that the Credential Manifest URL is in the same tenant Region and throw an error if it's not | ||
if (!authenticationArgs.credentialManifest.startsWith(msIdentityHostName)) { | ||
throw new Error(`Error in config file. CredentialManifest URL configured for wrong tenant region. Should start with:` + msIdentityHostName) | ||
} | ||
|
||
// get the Access Token | ||
try { | ||
const result = await cca.acquireTokenByClientCredential(msalClientCredentialRequest) | ||
if (result) { | ||
return result.accessToken | ||
} | ||
} catch { | ||
console.log('failed to get access token') | ||
resp.status(401).json({ | ||
error: 'Could not acquire credentials to access your Azure Key Vault', | ||
}) | ||
return | ||
} | ||
return '' | ||
}) | ||
return '' | ||
} | ||
|
||
/** | ||
* Not implemented yet | ||
* @param authenticationArgs | ||
* @constructor | ||
*/ | ||
export async function SilentFlowAuthenticator(authenticationArgs: IMsAuthenticationSilentFlowArgs): Promise<string> { | ||
throw new Error("This authentication method is not implemented yet.") | ||
} | ||
|
||
/** | ||
* necessary fields are: | ||
* azClientId: clientId of the application you're trying to login | ||
* azTenantId: your MS Azure tenantId | ||
* username: username of the user | ||
* password: password of the user | ||
* scopes: scopes that you want to access via this authentication | ||
* @param authenticationArgs | ||
* @constructor | ||
*/ | ||
export async function UsernamePasswordAuthenticator(authenticationArgs: IMsAuthenticationUsernamePasswordArgs): Promise<string> { | ||
const msalConfig = { | ||
auth: { | ||
clientId: authenticationArgs.azClientId, | ||
authority: 'https://login.microsoftonline.com/' + authenticationArgs.azTenantId, | ||
}, | ||
} | ||
const pca = new PublicClientApplication(msalConfig) | ||
return await pca | ||
.acquireTokenByUsernamePassword(authenticationArgs as UsernamePasswordRequest) | ||
.then((response: any) => { | ||
console.log('acquired token by password grant', response) | ||
return response | ||
}) | ||
.catch((error: any) => { | ||
console.log(error) | ||
}) | ||
} |
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,5 @@ | ||
export { AuthorizationCodeAuthenticator } from './MsAuthenticator' | ||
export { BehalfOfAuthenticator } from './MsAuthenticator' | ||
export { ClientCredentialAuthenticator } from './MsAuthenticator' | ||
export { SilentFlowAuthenticator } from './MsAuthenticator' | ||
export { UsernamePasswordAuthenticator } from './MsAuthenticator' |
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,2 @@ | ||
export * from './authenticators' | ||
export * from './types' |
2 changes: 1 addition & 1 deletion
2
...vc-api-issuer/src/types/IMsVcApiIssuer.ts → ...thenticator/src/types/IMsAuthenticator.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './IMsAuthenticator' |
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,7 @@ | ||
{ | ||
"extends": "../tsconfig-base.json", | ||
"compilerOptions": { | ||
"rootDir": "src", | ||
"outDir": "dist" | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
36 changes: 0 additions & 36 deletions
36
packages/ms-vc-api-issuer/__tests__/shared/vcApiIssuerClientCredentialAgentLogic.ts
This file was deleted.
Oops, something went wrong.
41 changes: 0 additions & 41 deletions
41
packages/ms-vc-api-issuer/__tests__/shared/vcApiIssuerUsernamePasswordAgentLogic.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.