我在应用程序的前端使用Angular 9。我正在使用AWS Amplify进行用户身份验证。我正在尝试将google注册与我的应用程序集成在一起。我可以使用google登录用户,但是登录后重定向用户时,似乎收到了无效的授权错误。
POST **domain_name** 400
ConsoleLogger.js:107 [ERROR] 54:09.165 OAuth - Error handling auth response. Error: invalid_grant
at OAuth.<anonymous> (OAuth.js:186)
at step (OAuth.js:56)
at Object.next (OAuth.js:37)
at fulfilled (OAuth.js:28)
at ZoneDelegate.invoke (zone-evergreen.js:364)
at Zone.run (zone-evergreen.js:123)
at zone-evergreen.js:857
at ZoneDelegate.invokeTask (zone-evergreen.js:399)
at Zone.runTask (zone-evergreen.js:167)
at drainMicroTaskQueue (zone-evergreen.js:569)
我在前端使用Auth.federatedSignIn
方法来调用API。这是auth.component.ts
import { Component, OnInit, OnDestroy, ChangeDetectorRef } from '@angular/core';
import { Amplify } from "aws-amplify";
import Auth, { CognitoHostedUIIdentityProvider } from "@aws-amplify/auth";
import { onAuthUIStateChange, CognitoUserInterface, AuthState, FormFieldTypes } from '@aws-amplify/ui-components';
async signInWithGoogle() {
console.log("signInWithGoogle called");
try {
Auth.federatedSignIn({'provider': CognitoHostedUIIdentityProvider.Google}).then(
cred => {
this.authState = AuthState.SignedIn;
console.log(cred);
}
).catch(
e => {
// console.log(e);
}
);
} catch (error) {
console.log("Error Calling signInWithGoogle");
}
}
然后我有一个按钮,单击该按钮将调用signInWithGoogle()
。在使用者选择他们的Google帐户后,就会发生上述错误。另外,我在app.module.ts文件中只调用一次Amplify.configure(awsconfig);
。