amplify-js | declarative JavaScript library for application development | AWS library
kandi X-RAY | amplify-js Summary
kandi X-RAY | amplify-js Summary
AWS Amplify provides a declarative and easy-to-use interface across different categories of cloud operations. AWS Amplify goes well with any JavaScript based frontend workflow and React Native for mobile developers. Our default implementation works with Amazon Web Services (AWS), but AWS Amplify is designed to be open and pluggable for any custom backend or service.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of amplify-js
amplify-js Key Features
amplify-js Examples and Code Snippets
import Amplify from '@aws-amplify/core'
import { Auth } from '@aws-amplify/auth'
import awsconfig from './aws-exports'
Amplify.configure(awsconfig)
Auth.configure(awsconfig)
Amplify.configure(awsconfig)
yarn add amazon-cognito-identity-js
{
"message": "Hello from AWS IoT console"
}
import { Auth } from 'aws-amplify'
export default {
async mounted() {
if (this.$store.state.account.authorized) {
return
}
try {
let user = await Auth.currentAuthenticatedUser({ bypassCache: false })
if (!
import Auth from '@aws-amplify/auth'
import { CognitoUser } from 'amazon-cognito-identity-js'
const CUSTOM_AUTH_TTL = 5 * 60 * 1000 // Milliseconds
interface CustomAuthSession {
username: string
session: string
// Milliseconds afte
import Amplify from 'aws-amplify'
import Auth from '@aws-amplify/auth'
let mfaRequired = false
Amplify.configure({
Auth: {
userPoolWebClientId: '',
userPoolId: ''
}
})
const logUserIn = (user) => {
// Go for
npm install --save aws-amplify
npm install --save aws-amplify-react
Amplify.configure({
"aws_project_region": process.env.REACT_APP_REGION,
"aws_cognito_identity_pool_id": process.env.REACT_APP_IDENTITY_POO
npm i aws-amplify --save
import Amplify, { Auth } from 'aws-amplify'
Amplify.configure({
Auth: {
region: process.env.AWS_REGION,
identityPoolId: process.env.IDENTITY_POOL_ID,
userPoolId: process.env.
import { Storage } from 'aws-amplify'
const getImgUrl = key => {
return Storage.get(key)
.then(res => (res))
.catch(err => console.log(err))
}
class Image extends Component {
this.state = {
imgSrc: null
import Amplify from 'aws-amplify'
import Amplify from '@aws-amplify/core'
import Auth from '@aws-amplify/auth'
import Amplify from 'aws-amplify'
var AWS = require('aws-sdk')
const CognitoExpress = require('cognito-express')
import { CognitoUserPool, CognitoUser } from 'amazon-cognito-identity-js'
exports.getUsersFromUserPool = (paramsObject, userP
Community Discussions
Trending Discussions on amplify-js
QUESTION
I'm experimenting with AWS amplify. In particular, looking to provide a means for a user to change their cognito password. I don't understand how that is done in a secure fashion given the client id is exposed.
What am I missing?
Here are the docs for what I'm using....
https://github.com/aws-amplify/amplify-js/tree/main/packages/amazon-cognito-identity-js
...ANSWER
Answered 2021-Dec-23 at 13:36Amplify uses amazon-cognito-identity-js
under the hood. So use Auth module from Amplify(aws-amplify
).
QUESTION
I have a user pool in Cognito, and right now I'm following https://github.com/aws-amplify/amplify-js/tree/main/packages/amazon-cognito-identity-js to authenticate user. I'm not using Amplify btw.
However in above link, I can only see example of authentication for identity pool.
...ANSWER
Answered 2021-Nov-15 at 07:43Cognito Identity JS is for identity pools i believe. Here's the javascript method to sign in to user pool and retrieve tokens. https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CognitoIdentityServiceProvider.html#initiateAuth-property
QUESTION
I try to mock Auth.currentSession() for jest testing.
I tried to write code according to this article.
https://github.com/aws-amplify/amplify-js/issues/3605
But it does not work. It makes compile errors.
ANSWER
Answered 2021-Sep-21 at 12:59I just can avoid compile error by adding @ts-ignore
QUESTION
I am writing here to ask for help or at least a clarification.
I work at a startup and a couple of weeks ago we launched our SaaS. We manage all our users with Aws Cognito. I'm using amazon-cognito-identity-js
for the authentication on the frontend and both sign-up and sign-in work fine. We want to add social sign-in (OAuth) through Google and for that I'm using aws-amplify-js
, calling Auth.federatedSignIn({provider: 'Google'})
as specified in Amplify docs.
The first time a user sign in with Google, a new user is correctly created in Cognito, but if I try to sign in again with the same user I get the following error: #error_description=Invalid+user+attributes%3A+email%3A+Attribute+cannot+be+updated.%0A+&error=invalid_request
.
Apparently this is a rather common issue:
- https://github.com/amazon-archives/amazon-cognito-auth-js/issues/159
- https://github.com/amazon-archives/amazon-cognito-auth-js/issues/48
- https://github.com/aws-amplify/amplify-js/issues/3526
After looking for a solution I believe this happens because when we created our User Pool we set email
as a required attribute and it was automatically set as immutable. Apparently if you want to use social sign-in every attribute should be mutable (as specified here because on every new sign in Cognito tries to update them.
So now we're stuck. It's not possible to change email
attribute from immutable
to mutable
for an existing User Pool and as far as I know it's not possible to prevent Auth.federatedSignIn({provider: 'Google'})
to update every user attributes.
We cannot simply delete and recreate our User Pool because we're already in production and we got several users already registered. Is there any possible solution or workaround to fix this? Any kind of suggestion would be very helpful!
...ANSWER
Answered 2021-Sep-15 at 07:24As of now there is nothing more you could do then to migrate all the users to another User Pool.
For users using federated sign in this won't change anything. You don't store their passwords so they won't see any difference.
The problem starts with users for which you has passwords. While you can migrate them to another pool, they will have to set up a new password.
You could write a simple script that could create a CSV file with the user data and then use the import function of the new User Pool to import all users. All non-federate users will then need to set new password.
You can just notify all of them that this will be happening because the whole operation will involve some downtime (since you don't want the two pools to get out of sync).
QUESTION
I am developing using react-native with Amazon AWS as back-end. I am also using amplify
library.
For logging in, I am using the below call:
const user = await Auth.signIn(...)
https://docs.amplify.aws/lib/auth/emailpassword/q/platform/js#sign-in
https://aws-amplify.github.io/amplify-js/api/classes/authclass.html#signin
My related questions:
I get a big JSON in the
user
variable. I believe it is theAWS credential
?The above
signIn()
call DOES NOT return a JWT token, it returns AWS credential. Is it? Also see the post:- https://stackoverflow.com/a/59327655/15943787Above post mentions:
After successfully authenticating a user, Amazon Cognito issues JSON web tokens (JWT) that you can use to secure and authorize access to your own APIs, or exchange for AWS credentials
What is meant by above statement? What is Auth.signIn()
doing? getting JWT token or credentials?
Does this returned credential get stored inside the mobile device? By default in android it is stored un-encrypted. Right?
Is it stored in sharedPreferences?
ANSWER
Answered 2021-Jun-18 at 14:39The Auth.signIn()
returns a CognitoUser
Object as defined in the API Docs.
Below is from AWS SDK for Android but the data in Javascript is the same, (found here). The JWT Token in stored in the CognitoUser.CognitoUserSession
attribute.
Represents a single Cognito User. This class encapsulates all operations possible on a user and all tokens belonging to the user. The user tokens, as CognitoUserSession, are stored in SharedPreferences. Only the tokens belonging to the last successfully authenticated user are stored
So to answer your questions:
- I get a big JSON in the user variable. I believe it is the AWS credential?
The user variable is a CognitoUser Object, which represents a single CognitoUser. to get the JWT token try user.sessionId
or user.tokenId
- The above signIn() call DOES NOT return a JWT token, it returns AWS credential. Is it? Also see the post:- https://stackoverflow.com/a/59327655/15943787
It updates the CognitoUser with session and token JWT. Check the user object to find them, after Auth.signIn() the user Object would have updated if AWS issued tokens
- Does this returned credential get stored inside the mobile device? By default in android it is stored un-encrypted. Right?
Its being stores in Shared Preferences. so yes it's on device and un-encrypted. But AWS manages updating the and changing the JWT as the user interacts with cognito automatically.
- Is it stored in sharedPreferences?
Yes, it is stored in sharedPreferences
QUESTION
I am facing a problem with my React Native Android project. I am currently working on integrating AWS Amplify Push Notifications. I am receiving the following "Duplicate Classes" dependency error and I don't know, where it might originate from. Do you have a solution for this problem?
What I already did:
- I found this ticket here https://github.com/facebook/react-native/issues/27493 which seemed to indicate that there might be an issue using react-native-device-info which was the case for me. So I removed this library and replaced it with react-native-version-info. But the problem persists.
- I checked this ticket https://github.com/dantasfiles/AmplifyAndroidPush/issues/1 - when running
./gradlew :app:dependencies > ../dependencies.txt
, I get the dependency tree and can see thatcom.firebase:firebase-jobdispatcher:0.6.0
seems to be solely used by aws amplify push notifications. But still I do not know what to do about this now:
ANSWER
Answered 2021-Jun-09 at 05:00Hi stackoverflow community,
after about a week of investigating and also opening a ticket in the aws-amplify-js github project, I was now able to solve the problem. In the following, I want to describe the solution if any of you might face the same problem in the future.
Here's the github ticket I had created on aws-amplify-js: https://github.com/aws-amplify/amplify-js/issues/8389
In my app/build.gradle I had the following definitions related to firebase and play-services:
QUESTION
I am working on a project where we have existing Google Sign-in and we would like to convert to AWS Cognito so we can get username and password authentication as well as other social logins such as Facebook in the near future. In a feature branch of our API, we have working Cognito authentication via JWT. My current issue is exchanging the Google authentication response payload for Cognito's JWT.
In our JavaScript, I am able to get a Google authentication response object that has the tokenId
field. It is my understanding that I should be able to exchange that with Cognito for their JWT that I can use for interacting with my API. I have the Google app created and configured in the Cognito User Pool.
What has been frustrating in trying to figure this out is that all the documentation seems to focus on new apps or just on the hosted UI for Cognito. I have dug through GitHub issues and blog posts that claim this should be easy. I'm hopeful I'm missing something easy.
For reference, here is the code I have to sign in with Cognito and extract the JWT.
...ANSWER
Answered 2021-Jun-05 at 05:23Have you configured Google as a federated IdP in your Cognito user pool? https://aws.amazon.com/premiumsupport/knowledge-center/cognito-google-social-identity-provider/
QUESTION
I have a Javascript backend (NestJS with Express + Passport).
I would like to outsource the complexity of authentication (e.g. social auth) to Cognito but avoid getting locked in. I was wondering if I can use Cognito as a provider in Passport, similar to social providers (Google, Facebook, etc). That way, I could integrate many providers with the effort of integrating just one. I would still manage user data, authorization, etc in my own app, therefore, if I wanted to in the future, I could implement Google, Facebook, etc. social auth in my own app and get rid of Cognito.
If I understand it correctly this is possible with Auth0.
Ideally, I would like to implement an OAuth flow where the user is redirected to a simple "sign up / log in" Cognito app, logs in, gets redirected to a callback URL in my app where I receive user data. If AWS doesn't host a solution for this, I can also use their UI elements to build & host this app.
If implemented as a provider / strategy, this could be as simple as:
...ANSWER
Answered 2021-Apr-24 at 14:30If you are already getting your hands dirty managing your user data I would integrate directly with the social providers. Cognito is most useful as a cheap and dirty place store user data and to host managed authentication and authorization services. You are already storing your own user data and sounds like you are only supporting social login; Cognito might be more of hindrance in this situation.
Additonally, there isn't some magic that powers cognito social logins, you have to go through the same configuration steps if you were integrating directly, only difference is cognito will act as the callback endpoint.
But if you want to forge ahead while avoiding vendor lock-in use it strictly as an OIDC service provider and use a generic OIDC strategy with passport or just remove passport altogether as you don't really need it in this situation, then as auth0 recommends use the oidc express middleware to protect your endpoints and use something like AppAuth to get the access token in your frontend.
QUESTION
We are moving our auth to Cognito and need to alter the token we get from Cognito. We are using a Pre Token Generation Lambda Trigger to accomplish this. We are also using Amplify's Auth library. However, I can not access the clientMetadata we are sending with Auth.signIn()
.
On the front-end we simply have:
...ANSWER
Answered 2021-Feb-22 at 23:11Try setting the metadata value using Auth.configure
before executing Auth.signIn
. On one hand, it doesn't look like the sign-in event is a pre-token lambda trigger, which explains why the metadata isn't being passed. I appreciate that this is not especially intuitive. That said, on the other hand and assuming you will need to access the same metadata value when tokens are generated as part of a refresh, you'll likely need to cover additional non-initial-signIn events anyways. Using Auth.configure
looks to do the trick for both.
QUESTION
I am using amazon-Cognito-identity-js
and aws-sdk
to setup authentication in my nodeJs app.
First i signup using userpool.signUp(..)
method according to docs.
Then i confirmed the verification code using cognitoUser.confirmRegistration(..)
method according to docs.
Up to here, everything works fine. But, now i would like to get all attributes of the user. I found a method cognitoUser.getUserAttributes(..)
which can give me attributes. But when i call this method after cognitoUser.confirmRegistration(..)
then it returns Error: User is not authenticated.
I went through a SO question where I got
getCurrentUser()
will return null at backend side.
So, how can I authorize any user at the fully secured backend side using nodejs?
...ANSWER
Answered 2021-Jan-30 at 08:57You have to first call the authenticateUser
method:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install amplify-js
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page