Skip to main content

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

Cognito (preflight class)

No description

Constructor

new(api: Api, props: CognitoProps?): Cognito

Properties

NameTypeDescription
clientIdstrNo description
identityPoolIdstrNo description
userPoolIdstrNo description

Methods

SignatureDescription
inflight adminConfirmUser(email: str): voidNo description
connect(path: str): voidNo description
delete(path: str): voidNo description
get(path: str): voidNo description
inflight getCredentialsForIdentity(token: str, identityId: str): JsonNo description
inflight getId(poolId: str, identityPoolId: str, token: str): strNo description
head(path: str): voidNo description
inflight initiateAuth(email: str, password: str): strNo description
options(path: str): voidNo description
patch(path: str): voidNo description
post(path: str): voidNo description
put(path: str): voidNo description
inflight signUp(email: str, password: str): voidNo description

platform.Cognito_tfaws (preflight class)

No description

Constructor

new(api: Api, props: CognitoProps?): Cognito_tfaws

Properties

NameTypeDescription
clientIdstrNo description
identityPoolIdstrNo description
userPoolIdstrNo description

Methods

SignatureDescription
static inflight _adminConfirmUser(poolId: str, email: str): voidNo description
static inflight _getCredentialsForIdentity(poolId: str, token: str, identityPoolId: str): JsonNo description
static inflight _getId(poolId: str, identityPoolId: str, token: str): strNo description
static inflight _initiateAuth(clientId: str, email: str, password: str): strNo description
static inflight _signUp(clientId: str, email: str, password: str): voidNo description
inflight adminConfirmUser(email: str): voidNo description
connect(path: str): voidNo description
delete(path: str): voidNo description
get(path: str): voidNo description
inflight getCredentialsForIdentity(token: str, identityId: str): JsonNo description
inflight getId(poolId: str, identityPoolId: str, token: str): strNo description
head(path: str): voidNo description
inflight initiateAuth(email: str, password: str): strNo description
options(path: str): voidNo description
patch(path: str): voidNo description
post(path: str): voidNo description
put(path: str): voidNo description
inflight signUp(email: str, password: str): voidNo description

platform.Cognito_sim (preflight class)

No description

Constructor

new(api: Api, props: CognitoProps?): Cognito_sim

Properties

No properties

Methods

SignatureDescription
inflight adminConfirmUser(email: str): voidNo description
connect(path: str): voidNo description
delete(path: str): voidNo description
get(path: str): voidNo description
inflight getCredentialsForIdentity(token: str, identityId: str): JsonNo description
inflight getId(poolId: str, identityPoolId: str, token: str): strNo description
head(path: str): voidNo description
inflight initiateAuth(email: str, password: str): strNo description
options(path: str): voidNo description
patch(path: str): voidNo description
post(path: str): voidNo description
put(path: str): voidNo description
inflight signUp(email: str, password: str): voidNo description

ICognito (interface)

No description

Properties

No properties

Methods

SignatureDescription
inflight adminConfirmUser(email: str): voidNo description
connect(path: str): voidNo description
delete(path: str): voidNo description
get(path: str): voidNo description
inflight getCredentialsForIdentity(token: str, identityId: str): JsonNo description
inflight getId(poolId: str, identityPoolId: str, token: str): strNo description
head(path: str): voidNo description
inflight initiateAuth(email: str, password: str): strNo description
options(path: str): voidNo description
patch(path: str): voidNo description
post(path: str): voidNo description
put(path: str): voidNo description
inflight signUp(email: str, password: str): voidNo description

CognitoProps (struct)

No description

Properties

NameTypeDescription
authenticationTypeAuthenticationType?No description
autoVerifiedAttributes
Array?
No description
headerKeystr?No description
namestr?No description
schemaJson?No description
usernameAttributes
Array?
No description

AuthenticationType (enum)

No description

Values

NameDescription
AWS_IAMNo description
COGNITO_USER_POOLSNo description