我在使用带有nativescript-angular的Google使用oauth-2时遇到了一些问题。开头的代码是
public onTapLogin() {
console.log("I'm in onTapLogin");
this.authService
.tnsOauthLogin("google")
.then((result: ITnsOAuthTokenResult) => {
console.log("back to login component with token " + result.accessToken);
this.routerExtensions
.navigate(["../register"])
.then(() => console.log("navigated to /authenticated"))
.catch(err => console.log("error navigating to /authenticated: " + err));
})
.catch(e => console.log("Error: " + e));
this.authService.tnsRefreshOAuthAccessToken()
}
}
先调用onTapLogin,然后再调用tnsOAuthLogin。
public tnsOauthLogin(providerType): Promise<ITnsOAuthTokenResult> {
this.client = new TnsOAuthClient(providerType);
console.log('im in authservice.tnsoauthlogin ')
return new Promise<ITnsOAuthTokenResult>((resolve, reject) => {
console.log('im just calling loginWithCompletion')
this.client.loginWithCompletion(
(tokenResult: ITnsOAuthTokenResult, error) => {
if (error) {
console.error("back to main page with error: ");
console.error(error);
reject(error);
} else {
console.log("back to main page with access token: ");
console.log(tokenResult);
resolve(tokenResult);
}
}
);
});
}
在调用loginWithCompletion之后,我收到标题中描述的错误。我收到的最后一条日志是“我只是调用loginWithCompletion”。在那之后没什么。
在调用引导程序之前,我还注册了clientId和其他设置
export function configureOAuthProviders(){
console.log('caalling configure oauthProvider');
const googleProvider = configureOAuthProviderGoogle();
configureTnsOAuth([googleProvider]);
}
export function configureOAuthProviderGoogle(): TnsOaProvider{
const googleProviderOptions: TnsOaProviderOptionsGoogle={
openIdSupport:"oid-full",
clientId:"********************",
redirectUri:"*****************:/auth",
urlScheme:"********************",
scopes:["email"]
};
const googleProvider = new TnsOaProviderGoogle(googleProviderOptions);
return googleProvider;
}
最后是我的AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="__PACKAGE__"
android:versionCode="1"
android:versionName="1.0">
<supports-screens
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"/>
<uses-sdk
android:minSdkVersion="17"
android:targetSdkVersion="__APILEVEL__"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:name="com.tns.NativeScriptApplication"
android:allowBackup="true"
android:icon="@drawable/icon"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name="com.tns.NativeScriptActivity"
android:label="@string/title_activity_kimera"
android:launchMode="singleTask"
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|locale|uiMode"
android:theme="@style/LaunchScreenTheme">
<meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="***********"/>
</intent-filter>
</activity>
<activity android:name="com.tns.ErrorReportActivity"/>
</application>
</manifest>
其中android:scheme具有与urlscheme设置相同的网址。
有人对此有线索吗?任何建议将不胜感激。
我尝试将我的Oauth google设置放在由nativescript由alex ziskind提供给我们的示例中,看来工作正常