我使用 aws 身份验证创建了一个 React 应用程序,
`从“aws-amplify”导入{放大}; 从“../aws-exports”导入 awsmobile; 从“@aws-amplify/ui-react”导入 { Authenticator, Flex }
Amplify.configure(awsmobile)
const 登录 = () => { 返回(
<div>
<Authenticator>
{({ signOut, user }) => (
<div className="App">
<p onClick={() => { }}>
Hey {user.username}, welcome to my channel, with auth!
</p>
<button onClick={signOut}>Sign out</button>
</div>
)}
</Authenticator>
</div>
)
} `
我的要求是开发其他应用程序,并且使用oauth,我需要来自该应用程序cognito的访问令牌
请给我一个解决方案
这是例子:
import { fetchAuthSession } from 'aws-amplify/auth';
async function currentSession() {
try {
const { accessToken, idToken } = (await fetchAuthSession()).tokens ?? {};
} catch (err) {
console.log(err);
}
}
来自 Amplify 官方文档的更多详细信息:管理用户会话和凭据