javascript - Can i use my own sign in form for aws cognito? - Stack Overflow

I have a nextjs app that use aws cognito for auth. i was wondering if there is a way to replace the hos

I have a nextjs app that use aws cognito for auth. i was wondering if there is a way to replace the hosted ui provided by aws with my own custom form.

import { Domain } from "@material-ui/icons";
import NextAuth from "next-auth";
import Providers from "next-auth/providers";

export default NextAuth({
    providers:[
        Providers.Cognito({
            clientId:process.env.COGNITO_CLIENT,
            clientSecret:process.env.COGNITO_CLIENT_SECRET,
            domain: process.env.COGNITO_DOMAIN
        })

        
    ]
})

I have a nextjs app that use aws cognito for auth. i was wondering if there is a way to replace the hosted ui provided by aws with my own custom form.

import { Domain } from "@material-ui/icons";
import NextAuth from "next-auth";
import Providers from "next-auth/providers";

export default NextAuth({
    providers:[
        Providers.Cognito({
            clientId:process.env.COGNITO_CLIENT,
            clientSecret:process.env.COGNITO_CLIENT_SECRET,
            domain: process.env.COGNITO_DOMAIN
        })

        
    ]
})
Share Improve this question asked Nov 26, 2021 at 5:51 Nahashon MuriithiNahashon Muriithi 911 silver badge4 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 9

Technically, yes it is possible, but @alexrogo answer is misleading. Amplify, apart from being highly questionable (just look at open tickets on github), doesn't use OpenIDConnect standard. It's doing direct Cognito initiateAuth operation which returns tokens without openid scope. If you try to call e.g. /userinfo endpoint on Cognito, that will fail. Also Amplify keeps tokens in either local storage or cookies depending how you configure it but it's no httponly cookie... That's very troublesome.

But that being said, it is possible to replace HostedUI but beware, as HostedUI is not just a UI! It's a full authorization server. And you have to implement those functionalities yourself if you want to omit its login page. See here for more details: AWS Cognito Authorization code grant flow without using the hosted UI

Yes, this is possible.

You can connect your own UI ponents to Cogntio's APIs. You can store your authentication token in the state or localstorage. Take a look at this Documentation.

There you will find every neccesary function, including Sign Up, Sign In, Log out, Change User Attributes, refreshing tokens.

Just to follow up with @alexrogo Amplify has a whole built in UI connected ponent system, so you don't have to build your custom UI by yourself. This is the getting started guide.

The default flow when you setup a new user pool with Amplify is the USER_SRP_AUTH flow. The Cognito Hosted UI has options for OAuth 2.0 federation and OpenID Connect

With that said, if you prefer, you can setup federated OAuth 2.0 accounts with the Amplify UI, as seen here.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743782844a4506120.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信