Amazon Cognito
A wing library to work with AWS Cognito.
Prerequisites
Installation
sh npm i @winglibs/cognito
Usage
bring cloud;
bring cognito;
let api = new cloud.Api();
api.get("/hello", inflight (req) => {
return {
status: 200
};
});
let auth = new cognito.Cognito(api);
auth.get("/hello");
Test
Wing Code
bring expect;
bring http;
test "auth happy path" {
auth.signUp("fakeId@wing.cloud", "This-is-my-test-99!");
auth.adminConfirmUser("fakeId@wing.cloud");
let token = auth.initiateAuth("fakeId@wing.cloud", "This-is-my-test-99!");
let res = http.get("{api.url}/hello", headers: {
"Authorization": "Bearer {token}"
});
expect.equal(res.status, 200);
}
AWS CLI
Create a user
aws cognito-idp sign-up \
--client-id ${USER_POOL_CLIENT_ID} \
--username eyalk@monada.co \
--password NicePassw0rd! \
--user-attributes Name=name,Value=ekeren Name=email,Value=eyalk@monada.co
Get a token for the user (make sure user is confirmed)
aws cognito-idp initiate-auth \
--client-id ${USER_POOL_CLIENT_ID} \
--auth-flow USER_PASSWORD_AUTH \
--auth-parameters USERNAME=eyalk@monada.co,PASSWORD=NicePassw0rd! \
--query 'AuthenticationResult.IdToken' \
--output text
Send a request
curl -H "Authorization: ${TOKEN}" https://5b0y949eik.execute-api.us-east-1.amazonaws.com/prod/hello
License
This library is licensed under the MIT License.
API Reference
Table of Contents
- Classes
- Interfaces
- Structs
- Enums
Cognito (preflight class)
No description
Constructor
new(api: Api, props: CognitoProps?): Cognito
Properties
Name | Type | Description |
---|---|---|
clientId | str | No description |
identityPoolId | str | No description |
userPoolId | str | No description |
Methods
Signature | Description |
---|---|
inflight adminConfirmUser(email: str): void | No description |
connect(path: str): void | No description |
delete(path: str): void | No description |
get(path: str): void | No description |
inflight getCredentialsForIdentity(token: str, identityId: str): Json | No description |
inflight getId(poolId: str, identityPoolId: str, token: str): str | No description |
head(path: str): void | No description |
inflight initiateAuth(email: str, password: str): str | No description |
options(path: str): void | No description |
patch(path: str): void | No description |
post(path: str): void | No description |
put(path: str): void | No description |
inflight signUp(email: str, password: str): void | No description |
platform.Cognito_tfaws (preflight class)
No description
Constructor
new(api: Api, props: CognitoProps?): Cognito_tfaws
Properties
Name | Type | Description |
---|---|---|
clientId | str | No description |
identityPoolId | str | No description |
userPoolId | str | No description |
Methods
Signature | Description |
---|---|
static inflight _adminConfirmUser(poolId: str, email: str): void | No description |
static inflight _getCredentialsForIdentity(poolId: str, token: str, identityPoolId: str): Json | No description |
static inflight _getId(poolId: str, identityPoolId: str, token: str): str | No description |
static inflight _initiateAuth(clientId: str, email: str, password: str): str | No description |
static inflight _signUp(clientId: str, email: str, password: str): void | No description |
inflight adminConfirmUser(email: str): void | No description |
connect(path: str): void | No description |
delete(path: str): void | No description |
get(path: str): void | No description |
inflight getCredentialsForIdentity(token: str, identityId: str): Json | No description |
inflight getId(poolId: str, identityPoolId: str, token: str): str | No description |
head(path: str): void | No description |
inflight initiateAuth(email: str, password: str): str | No description |
options(path: str): void | No description |
patch(path: str): void | No description |
post(path: str): void | No description |
put(path: str): void | No description |
inflight signUp(email: str, password: str): void | No description |
platform.Cognito_sim (preflight class)
No description
Constructor
new(api: Api, props: CognitoProps?): Cognito_sim
Properties
No properties
Methods
Signature | Description |
---|---|
inflight adminConfirmUser(email: str): void | No description |
connect(path: str): void | No description |
delete(path: str): void | No description |
get(path: str): void | No description |
inflight getCredentialsForIdentity(token: str, identityId: str): Json | No description |
inflight getId(poolId: str, identityPoolId: str, token: str): str | No description |
head(path: str): void | No description |
inflight initiateAuth(email: str, password: str): str | No description |
options(path: str): void | No description |
patch(path: str): void | No description |
post(path: str): void | No description |
put(path: str): void | No description |
inflight signUp(email: str, password: str): void | No description |
ICognito (interface)
No description
Properties
No properties
Methods
Signature | Description |
---|---|
inflight adminConfirmUser(email: str): void | No description |
connect(path: str): void | No description |
delete(path: str): void | No description |
get(path: str): void | No description |
inflight getCredentialsForIdentity(token: str, identityId: str): Json | No description |
inflight getId(poolId: str, identityPoolId: str, token: str): str | No description |
head(path: str): void | No description |
inflight initiateAuth(email: str, password: str): str | No description |
options(path: str): void | No description |
patch(path: str): void | No description |
post(path: str): void | No description |
put(path: str): void | No description |
inflight signUp(email: str, password: str): void | No description |
CognitoProps (struct)
No description
Properties
Name | Type | Description |
---|---|---|
authenticationType | AuthenticationType? | No description |
autoVerifiedAttributes |
| No description |
headerKey | str? | No description |
name | str? | No description |
schema | Json? | No description |
usernameAttributes |
| No description |
AuthenticationType (enum)
No description
Values
Name | Description |
---|---|
AWS_IAM | No description |
COGNITO_USER_POOLS | No description |