在uni-app里使用identity server4登录

服务器端配置:

复制代码
                    Client oneResult = new Client
                    {
                        ClientId = "localHtml",
                        ClientName = "test",
                        AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
                        ClientSecrets = { new Secret("1".Sha256()) },
                        AllowOfflineAccess = true,
                        RequireConsent = false,
                        RequireClientSecret = false,
                        AllowedScopes = { "openid", "sid" },
                        AuthorizationCodeLifetime = 36000,
                        IdentityTokenLifetime = 36000,
                        UserSsoLifetime = 36000
                    };
复制代码

 

uni端调用:

复制代码
                        uni.request({
                            url: baseUrl + '/connect/token',
                            method: 'POST',
                            header: {
                                'content-type': "application/x-www-form-urlencoded"
                            },
                            data: {
                                    username: this.user_name,
                                    password: this.password,
                                    grant_type: 'password',
                                    client_id: 'localHtml'
                            },
                            success: res => {
                                    console.log(res);
                                    if (res.statusCode === 200) {
                                        uni.setStorageSync('access_token', res.data.token_type + ' ' + res.data.access_token);
                                        uni.setStorageSync('user_name', this.user_name);
                                        uni.showToast({
                                            icon: 'none',
                                            title: '登录成功! '
                                        })
                                    } else {
                                        uni.showToast({
                                            icon: 'none',
                                            title: '登录失败! ['+res.statusCode+"] 请检查用户名/密码是否输入正确,或手机网络!",
                                            duration:3000
                                        })
                                    }
                            },
                            fail(e) {
                                console.log(e);
                            }
                        })
复制代码

 

posted @   星星c#  阅读(414)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
历史上的今天:
2018-05-04 iis 503 错误 Windows 不能让您登录,因为不能加载您的配置文件。请检查您是否连接到网络
点击右上角即可分享
微信分享提示