-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3189 from Opetushallitus/tor-2210-oauth2-metadata…
…-route TOR-2210 OmaData OAuth2 metadata route ja ensimmäinen versio rajapinnan dokumentaatiosta
- Loading branch information
Showing
19 changed files
with
496 additions
and
99 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
72 changes: 0 additions & 72 deletions
72
omadata-oauth2-sample/server/src/config/oauth-client-config.ts
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
omadata-oauth2-sample/server/src/config/oauth2-client-config.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,50 @@ | ||
import * as client from 'openid-client' | ||
import { Configuration } from 'openid-client' | ||
import { memoize } from '../util/memoize.js' | ||
import { enableLocalMTLS, getClientCertSecret } from './client-cert-config.js' | ||
import * as undici from 'undici' | ||
import { koskiBackendHost } from './koski-backend-config.js' | ||
|
||
const clientId = process.env.CLIENT_ID || 'oauth2client' | ||
const clientMetadata: client.ClientMetadata = { | ||
client_id: clientId, | ||
use_mtls_endpoint_aliases: false | ||
} | ||
export const getOAuthClientConfig = memoize( | ||
async (): Promise<Configuration> => { | ||
const discoveryOptions = enableLocalMTLS | ||
? { | ||
execute: [client.allowInsecureRequests] | ||
} | ||
: undefined | ||
|
||
let config = await client.discovery( | ||
new URL( | ||
`${koskiBackendHost}/koski/omadata-oauth2/.well-known/oauth-authorization-server` | ||
), | ||
clientId, | ||
clientMetadata, | ||
client.TlsClientAuth(), | ||
discoveryOptions | ||
) | ||
|
||
const certs = await getClientCertSecret() | ||
|
||
const options = { | ||
cert: certs['fullchain.pem'], | ||
key: certs['privkey.pem'] | ||
} | ||
|
||
const agent = new undici.Agent({ connect: options }) | ||
config[client.customFetch] = (...args) => | ||
// @ts-expect-error | ||
undici.fetch(args[0], { ...args[1], dispatcher: agent }) | ||
|
||
if (enableLocalMTLS) { | ||
client.allowInsecureRequests(config) | ||
} | ||
|
||
return config | ||
}, | ||
() => 'oauthClientConfig' | ||
) |
2 changes: 1 addition & 1 deletion
2
omadata-oauth2-sample/server/src/oauth2-client/oauth2-client.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
Oops, something went wrong.