我有以下客户:
new Client
{
ClientId = "nativeapptest",
ClientName = "Native App Test",
Enabled = true,
RequireClientSecret = false,
AllowedGrantTypes = GrantTypes.Code,
RedirectUris = { "com.mysite.nativeapp.12365789785256-buv2dwer7jjjjv5fckasdftn367psbrlb:/home" },
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
"MyScope"
},
RequirePkce = false,
AllowOfflineAccess = true,
RequireConsent = false
}
我正在使用 native 脚本构建一个可以使用 Identity Server 4 登录的 android 应用程序。目前发生的是我通过打开浏览器并使用所有正确的 OpenID 配置向 IS4 发出请求,我最终然后我选择使用 Google 登录的登录屏幕。进入谷歌后,我输入我的电子邮件和密码,一切正常,然后谷歌试图将我送回我的网站,但它只是挂起......它是一个没有加载任何内容的白页,它永远坐在那里,没有错误据我所知,is4 记录的消息。
nativescript 上面的登录部分来自 OAutho2 库 https://www.npmjs.com/package/nativescript-oauth2
我试图了解这是否是 IS4 或 native Android 应用程序上的问题。页面挂起是因为它正在等待 android 应用程序接管登录工作吗?也许问题出在 RedirectURI 方案上?
挂载的URL如下:
编辑:
由于我是在实际服务器上运行它,所以我无法直接调试它,但是,我确实添加了日志以查看代码执行了多远。我的日志告诉我用户是通过 google 和我的系统登录的,我的日志还显示 ExternalCallback 已将页面重定向到
/connect/authorize/callback?client_id=nativeapptest&response_type=code&redirect_uri=com.mysite.nativeapp%3A%2F%2Fhome&scope=openid%20profile%20MyScope&response_mode=query&state=abcd
此时,页面挂起。
请注意,我们将 RedirectUri 更改为 com.mysite.nativeapp 以帮助进行测试。
最后,我不确定这是否重要,但我们没有使用 https,因为这仍处于开发阶段。
最佳答案
刚刚完成示例应用程序
步骤01
我们将打开一个运行窗口
在键盘上按下
Windoes Key + R
等待
步骤02
我们将打开一个cmd窗口
在运行窗口文本输入写入
cmd
在键盘上按下
Enter
步骤03
我们将创建一个目录并将其作为我们 cmd 的工作目录
在CMD窗口写
mkdir D:\Experiments\E.IDser.NativeScript
cd /d D:\Experiments\E.IDser.NativeScript
步骤04
我们将克隆示例项目
在CMD窗口写
git clone https://github.com/Elrashid/nativescript-client-and-identity-server-sample.git
cd nativescript-client-and-identity-server-sample
步骤05
现在将运行应用程序
在CMD窗口写
Start.bat
步骤06
使用方法
为什么
1 app
+---+
|
identity |
2 server |
|
|
|
3 google +-+ user
| intractiom
|
| your
identity | app
4 server | <---+ stop
+---+ here
5 app +---+
|
|
|
identity +--+ background
6 server |
|
|
7 app |
+--+
见 register a custom URL scheme for Android
<data
android:path="/home"
android:scheme="com.mysite.nativeapp
.12365789785256-buv2dwer7
jjjjv5fckasdftn367psbrlb"
/>
你也可以试试
tns debug android
错误无法访问此站点
Identity Server 和 Native-Script 之间的通信
运行
nativescript-client-and-identity-server-sample/Start.bat
不跑就跑
"nativescript-client-and-identity-server-sample/identity-server/Start.bat" "nativescript-client-and-identity-server-sample/nativescript-client/Start.bat"
native 脚本应用程序应在 android 模拟器中运行
身份服务器应该在本地机器的 5010 端口运行
检查您可以打开的 windows 浏览器
http://localhost:5010
如果是
检查您可以打开的**android 模拟器**浏览器
http://10.0.2.2:5010
什么是 10.0.2.2?
special alias to your android emulator host loopback interface
我可以更改主机 10.0.2.2 的位置吗?
打开 nativescript-client\app\my-oauth-provider.ts
public authority = "http://10.0.2.2:5010"; public tokenEndpointBase = "http://10.0.2.2:5010"; public cookieDomains = ["10.0.2.2:5010"];
更改 http://10.0.2.2:5010到您的网址
关于c# - Identity Server 4/nativescript 挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53980826/