-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update AWS Cognito authentication example for 2.x.x (#55)
* Update auth-cognito for HB 2.x.x * Add AWS error middleware to diagnose AWS errors * Update READMEs * Use HummingbirdRouter * Remove commented out code
- Loading branch information
1 parent
97aaf0b
commit 6cc2e32
Showing
12 changed files
with
298 additions
and
265 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import Hummingbird | ||
import HummingbirdAuth | ||
import HummingbirdRouter | ||
import ServiceLifecycle | ||
import SotoCognitoAuthenticationKit | ||
|
||
struct AWSClientService: Service { | ||
let client: AWSClient | ||
|
||
func run() async throws { | ||
await GracefulShutdownWaiter().wait() | ||
try await self.client.shutdown() | ||
} | ||
} | ||
|
||
func buildApplication(configuration: HBApplicationConfiguration) throws -> some HBApplicationProtocol { | ||
// setup Soto | ||
let awsClient = AWSClient(httpClientProvider: .createNew) | ||
let cognitoIdentityProvider = CognitoIdentityProvider(client: awsClient, region: .euwest1) | ||
// setup SotoCognitoAuthentication | ||
let env = try HBEnvironment().merging(with: .dotEnv()) | ||
guard let userPoolId = env.get("cognito_user_pool_id"), | ||
let clientId = env.get("cognito_client_id") | ||
else { | ||
preconditionFailure("Requires \"cognito_user_pool_id\" and \"cognito_client_id\" environment variables") | ||
} | ||
let config = CognitoConfiguration( | ||
userPoolId: userPoolId, | ||
clientId: clientId, | ||
clientSecret: env.get("cognito_client_secret"), | ||
cognitoIDP: cognitoIdentityProvider, | ||
adminClient: true | ||
) | ||
let authenticatable = CognitoAuthenticatable(configuration: config) | ||
|
||
let router = HBRouterBuilder(context: AuthCognitoRequestContext.self) { | ||
AWSErrorMiddleware() | ||
UserController(cognitoAuthenticatable: authenticatable, cognitoIdentityProvider: cognitoIdentityProvider).endpoints | ||
} | ||
|
||
var app = HBApplication(router: router) | ||
app.addServices(AWSClientService(client: awsClient)) | ||
return app | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.