Universal Web SDK
npm install @locii/universal-login-sdkThis SDK is a wrapper for adding Biopass Multifactor authentications to applications which had their users in AWS Cognito.
Install the package
``bash`
npm install @locii/biopass-cognito-sdk
To import @locii/biopass-cognito-sdk, run the following command
`bash
import { BiopassAuth } from "@locii/biopass-cognito-sdk";
`
Step 1: Create config file
`javascript`
export const config = {
ClientId: '',
UserPoolId: '',
ClientMetadata: { redirectURI: 'http://localhost:3000/login' },
Auth: {
region: '',
userPoolId: '',
userPoolWebClientId: '',
authenticationFlowType: 'CUSTOM_AUTH'
}
};
ClientId: Biopass Client ID
UserPoolId: Cognito user pool ID
redirectURI: The user is redirected to this address after authentication.
Please make sure this is exactly same as the Allowed Callback URL setting in Biopass application.
userPoolWebClientId: Cognito Client ID
Step 2:
`javascript`
import { Amplify } from 'aws-amplify';
import config from './amplify-config';
Amplify.configure(config);
When signing in with user name and password, you will pass in the username and the password to the signin method of the Auth class.
`
import { BiopassAuth } from "@locii/biopass-cognito-sdk";
const login = async (event) => {
BiopassAuth.signin(username, password, config.ClientMetadata)
.then((res) => {
// add your code
})
.catch((err) => // add your code);
};
useEffect(() => {
BiopassAuth.resumeSignIn()
.then((user) => {
// add your code
})
.catch((err) => {
// add your code
});
}, []);
`
`
import { Auth } from 'aws-amplify';
async function signOut() {
try {
await Auth.signOut();
} catch (error) {
console.log('error signing out: ', error);
}
}
`
When signing in with user name and password, you will pass in the username and the password to the signin method of the Auth class.
Add a below command in Ployfills.ts
``
(window as any).global = window;
`
import { BiopassAuth } from "@locii/biopass-cognito-sdk";
ngOnInit() {
your code ...
BiopassAuth.resumeSignIn()
.then((user) => {
console.log('userr', user);
// add your code
})
.catch((err) => {
// add your code
});
}
login() {
BiopassAuth.signin(this.username.value, this.password.value, configClientMetadata)
.then((res) => {
// add your code
})
.catch((err) => // add your code);
}
`
`
import { Auth } from 'aws-amplify';
logout() {
try {
Auth.signOut();
} catch (error) {
console.log('error signing out: ', error);
}
}
`
When signing in with user name and password, you will pass in the username and the password to the signin method of the Auth class.
Add a below command in App.vue
``
var global = window
`
import { BiopassAuth } from "@locii/biopass-cognito-sdk";
created() {
BiopassAuth.resumeSignIn()
.then((user) => {
// add your code
})
.catch((err) => {
// add your code
})
},
methods: {
login() {
//add your code
BiopassAuth.signin(this.username, this.password, config.ClientMetadata)
.then((res) => {
// add your code
})
.catch((err) => console.log('asasasas'))
}
}
`
`
import { Auth } from 'aws-amplify';
logout() {
try {
Auth.signOut();
} catch (error) {
console.log('error signing out: ', error);
}
}
``