如何仅使用验证包配置Amplify ?



仅使用auth包(不是aws-sdk),我如何使用我的凭据配置Amplify ?

const {
Auth,
// configure?
} = require('@aws-amplify/auth')

Auth类上有一个configure方法。例子:

Auth.configure({
region: import.meta.env.VITE_AWS_REGION,
userPoolId: import.meta.env.VITE_USER_POOL_ID,
userPoolWebClientId: import.meta.env.VITE_USER_POOL_CLIENT_ID,
});

参考:https://github.com/aws-amplify/amplify-js/blob/6882c5e6e8f1bff2206ff0de74cebbcf87efd622/packages/auth/src/Auth.ts L141

这是来自Amplify doc的另一个例子。您有更多的选项参数来定制它。如果还有问题请告诉我。

Amplify.configure({
Auth: {
// (required) only for Federated Authentication - Amazon Cognito Identity Pool ID
identityPoolId: 'XX-XXXX-X:XXXXXXXX-XXXX-1234-abcd-1234567890ab',
// (required)- Amazon Cognito Region
region: 'XX-XXXX-X',
// (optional) - Amazon Cognito Federated Identity Pool Region
// Required only if it's different from Amazon Cognito Region
identityPoolRegion: 'XX-XXXX-X',
// (optional) - Amazon Cognito User Pool ID
userPoolId: 'XX-XXXX-X_abcd1234',
// (optional) - Amazon Cognito Web Client ID (26-char alphanumeric string, App client secret needs to be disabled)
userPoolWebClientId: 'a1b2c3d4e5f6g7h8i9j0k1l2m3',
// (optional) - Enforce user authentication prior to accessing AWS resources or not
mandatorySignIn: false,
// (optional) - Configuration for cookie storage
// Note: if the secure flag is set to true, then the cookie transmission requires a secure protocol
cookieStorage: {
// - Cookie domain (only required if cookieStorage is provided)
domain: '.yourdomain.com',
// (optional) - Cookie path
path: '/',
// (optional) - Cookie expiration in days
expires: 365,
// (optional) - See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie/SameSite
sameSite: 'strict' | 'lax',
// (optional) - Cookie secure flag
// Either true or false, indicating if the cookie transmission requires a secure protocol (https).
secure: true
},
// (optional) - customized storage object
storage: MyStorage,
// (optional) - Manually set the authentication flow type. Default is 'USER_SRP_AUTH'
authenticationFlowType: 'USER_PASSWORD_AUTH',
// (optional) - Manually set key value pairs that can be passed to Cognito Lambda Triggers
clientMetadata: { myCustomKey: 'myCustomValue' },
// (optional) - Hosted UI configuration
oauth: {
domain: 'your_cognito_domain',
scope: [
'phone',
'email',
'profile',
'openid',
'aws.cognito.signin.user.admin'
],
redirectSignIn: 'http://localhost:3000/',
redirectSignOut: 'http://localhost:3000/',
clientId: '1g0nnr4h99a3sd0vfs9',
responseType: 'code' // or 'token', note that REFRESH token will only be generated when the responseType is code
}
}
});

参考:https://docs.amplify.aws/lib/client-configuration/configuring-amplify-categories/q/platform/js/top-level-configuration

相关内容

  • 没有找到相关文章

最新更新