当前位置: 首页 > news >正文

服装网站建设方案摘要企业网络信息安全管理制度

服装网站建设方案摘要,企业网络信息安全管理制度,wordpress app弊端,商洛市城乡建设局网站目前正在使用asp.net core 2.0 (主要是web api)做一个项目, 其中一部分功能需要使用js客户端调用python的pandas, 所以需要建立一个python 的 rest api, 我暂时选用了hug, 官网在这: http://www.hug.rest/.目前项目使用的是identity server 4, 还有一些web api和js client.项目… 目前正在使用asp.net core 2.0 (主要是web api)做一个项目, 其中一部分功能需要使用js客户端调用python的pandas, 所以需要建立一个python 的 rest api, 我暂时选用了hug, 官网在这: http://www.hug.rest/.目前项目使用的是identity server 4, 还有一些web api和js client.项目的早期后台源码: https://github.com/solenovex/asp.net-core-2.0-web-api-boilerplate下面开始配置identity server 4, 我使用的是windows.添加ApiResource:在 authorization server项目中的配置文件添加红色部分, 这部分就是python hug 的 api:public static IEnumerableApiResource GetApiResources()        {            return new ListApiResource            {                new ApiResource(SalesApiSettings.ApiName, SalesApiSettings.ApiDisplayName) {                    UserClaims { JwtClaimTypes.Name, JwtClaimTypes.PreferredUserName, JwtClaimTypes.Email }                },                new ApiResource(purchaseapi, 采购和原料库API) {                    UserClaims { JwtClaimTypes.Name, JwtClaimTypes.PreferredUserName, JwtClaimTypes.Email }                },                new ApiResource(hugapi, Hug API) {                    UserClaims { JwtClaimTypes.Name, JwtClaimTypes.PreferredUserName, JwtClaimTypes.Email }                }            };        }修改js Client的配置:               // Sales JavaScript Client                new Client                {                    ClientId SalesApiSettings.ClientId,                    ClientName SalesApiSettings.ClientName,                    AllowedGrantTypes GrantTypes.Implicit,                    AllowAccessTokensViaBrowser true,                    AccessTokenLifetime 60 * 10,                    AllowOfflineAccess true,                    RedirectUris           { ${Startup.Configuration[MLH:SalesApi:ClientBase]}/login-callback, ${Startup.Configuration[MLH:SalesApi:ClientBase]}/silent-renew.html },                    PostLogoutRedirectUris { Startup.Configuration[MLH:SalesApi:ClientBase] },                    AllowedCorsOrigins     { Startup.Configuration[MLH:SalesApi:ClientBase] },                    AlwaysIncludeUserClaimsInIdToken true,                    AllowedScopes                     {                        IdentityServerConstants.StandardScopes.OpenId,                        IdentityServerConstants.StandardScopes.Profile,                        IdentityServerConstants.StandardScopes.Email,                        SalesApiSettings.ApiName,                        hugapi                    }                }修改js客户端的oidc client配置选项:添加 hugapi, 与authorization server配置对应.{        authority: http://localhost:5000,        client_id: sales,        redirect_uri: http://localhost:4200/login-callback,        response_type: id_token token,        scope: openid profile salesapi hugapi email,        post_logout_redirect_uri: http://localhost:4200,        silent_redirect_uri: http://localhost:4200/silent-renew.html,        automaticSilentRenew: true,        accessTokenExpiringNotificationTime: 4,        // silentRequestTimeout:10000,        userStore: new WebStorageStateStore({ store: window.localStorage })    }建立Python Hug api(可选) 安装virtualenv:pip install virtualenv然后在某个地方建立一个目录:mkdir hugapi cd hugapi建立虚拟环境:virtualenv venv激活虚拟环境:venv\Scripts\activate然后大约这样显示:安装hug:pip install hug这时, 参考一下hug的文档. 然后建立一个简单的api. 建立文件main.py:import hughug.get(/home)def root(): return Welcome home!运行:hug -f main.py结果好用:然后还需要安装这些:pip install cryptography pyjwt hug_middleware_cors其中pyjwt是一个可以encode和decode JWT的库, 如果使用RS256算法的话, 还需要安装cryptography. 而hug_middleware_cors是hug的一个跨域访问中间件(因为js客户端和这个api不是在同一个域名下).添加需要的引用:import hugimport jwtimport jsonimport urllib.requestfrom jwt.algorithms import get_default_algorithmsfrom hug_middleware_cors import CORSMiddleware然后正确的做法是通过Authorization Server的discovery endpoint来找到jwks_uri,identity server 4 的discovery endpoint的地址是:http://localhost:5000/.well-known/openid-configuration, 里面能找到各种节点和信息: 但我还是直接写死这个jwks_uri吧:response urllib.request.urlopen(http://localhost:5000/.well-known/openid-configuration/jwks) still_json json.dumps(json.loads(response.read())[keys][0])identity server 4的jwks_uri, 里面是public key, 它的结构是这样的:而我使用jwt库, 的参数只能传入一个证书的json, 也可就是keys[0].所以上面的最后一行代码显得有点.......如果使用python-jose这个库会更简单一些, 但是在我windows电脑上总是安装失败, 所以还是凑合用pyjwt吧.然后让hug api使用cors中间件:api hug.API(__name__) api.http.add_middleware(CORSMiddleware(api))然后是hug的authentication部分:def token_verify(token):    token token.replace(Bearer , )    rsa get_default_algorithms()[RS256]    cert rsa.from_jwk(still_json)    try:        result jwt.decode(token, cert, algorithms[RS256], audiencehugapi)        print(result)        return result    except jwt.DecodeError:        return Falsetoken_key_authentication hug.authentication.token(token_verify)通过rsa.from_jwk(json) 就会得到key (certificate), 然后通过jwt.decode方法可以把token进行验证并decode, 算法是RS256, 这个方法要求如果token里面包含了aud, 那么方法就需要要指定audience, 也就是hugapi.最后修改api 方法, 加上验证:hug.get(/home, requirestoken_key_authentication)def root(): return Welcome home!最后运行 hug api:hug -f main.py端口应该是8000.运行js客户端,登陆, 并调用这个hug api http://localhost:8000/home:(我的js客户端是angular5的, 这个没法开源, 公司财产, 不过配置oidc-client还是很简单的, 使用)返回200, 内容是: 看一下hug的log:token被正确验证并解析了. 所以可以进入root方法了. 其他的python api框架, 都是同样的道理.可以使用这个例子自行搭建 https://github.com/IdentityServer/IdentityServer4.Samples/tree/release/Quickstarts/7_JavaScriptClient 官方还有一个nodejs api的例子: https://github.com/lyphtec/idsvr4-node-jwks相关文章 基于OIDCOpenID Connect的SSO学习Identity Server 4的预备知识使用Identity Server 4建立Authorization Server (1)使用Identity Server 4建立Authorization Server (2)使用Identity Server 4建立Authorization Server (3)使用Identity Server 4建立Authorization Server (4)使用Identity Server 4建立Authorization Server (5)IdentityServer410- 添加对外部认证的支持之QQ登录spring cloud.net core搭建微服务架构Api授权认证六原文地址:https://www.cnblogs.com/cgzl/p/8270677.html.NET社区新闻深度好文欢迎访问公众号文章汇总 http://www.csharpkit.com
http://www.yutouwan.com/news/342083/

相关文章:

  • 阜阳公司做网站新做的网站如何备案
  • 网站建设报价是多少wordpress空间返回404
  • 新建网站怎么做高级seo是什么职位
  • 网站建设需要多长时间漳州微网站建设公司
  • 虎丘网站建设网站规划的主要内容
  • 中国建设网官方网站平台程序制作软件
  • 优化seo网站wordpress 加载完毕
  • 网站做推广需要多少钱百度seo是啥
  • 做网站南宁建立的近义词
  • 网站建设 报告wordpress 注册用户
  • 网站改版文案ui设计app界面设计流程
  • 怎么样做淘宝优惠券网站百度开放平台
  • 郑州网站设计推荐阳江 网站开发
  • 网站掉权重是怎么回事视频网站主持人
  • 电商网站平台建设视频公司简介模板素材
  • 公司网站建设需要注意哪些内容成品网站设计网站
  • 厦门做返利网站的公司凡科app制作
  • 宠物店网站建设方案head first wordpress
  • 西宁网站建设公司网站精神文件建设专栏
  • 苏州公司网站建设电话武邑县建设局网站
  • 皖icp备 网站建设男女做暖暖的视频试看网站
  • 网站做qq链接代码网页设计作业怎么打包
  • 淘宝网站怎么做的企业怎么做网站推广
  • 常州网站建设哪家好网站利润来源
  • 网站维护外包方案电子商务网站建设与维护 书
  • 美容医疗 网站建设php 网站 教程
  • 58同城网站招聘怎么做中企动力建站怎么样
  • 网站做优化效果怎样机械加工网站大全
  • 做网站的步骤阿里企业邮箱设置
  • 记事本代码做网站获取文章内容 wordpress