angular - 从 web.config 中的查询字符串中去除 URL
问题描述
我正在使用 Google 通过 OAuth2 对用户进行身份验证。该站点使用 Angular 5 构建并托管在 Azure 应用服务 (IIS) 中。当 google 对用户进行身份验证时,它会发回一个包含一些 URI 的 URL:
https://domain.azurewebsites.net/membership/oauth2?code=<authentication code>&scope=openid%20email%20https://www.googleapis.com/auth/plus.me%20https://www.googleapis.com/auth/userinfo.email
.
如您所见,在 之后&scope
,有 2 个 URI。azure 网站返回一个错误,表明
您要查找的资源已被删除、名称已更改或暂时不可用。
如果我从后面剥离查询字符串&scope
,它就可以正常工作。
我试图用重写规则去除 web.config 中的那部分:
<rule name="Remove paging parameters" stopProcessing="true">
<match url="^(.*)\/membership\/oauth2(.*)$" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="^(.*)(scope=.+)(.*)$" />
</conditions>
<action type="Redirect" url="{C:1}{C:3}" appendQueryString="false" />
</rule>
然而,什么也没有发生。任何帮助将不胜感激。
旁注:在 localhost 中一切正常,因为它是为 Angular 站点提供服务的 nodejs。该问题在 Azure 应用服务中引起,因为它由 IIS 提供服务。
解决方案
对于将来面临同样问题的任何人,我按照@kamranicus的回答解决了这个问题。该帖子中显示的正确重写网址如下:
<rule name="Google Login - Remove scope parameter" stopProcessing="true">
<match url="google/redirect/url(.*)?$" />
<conditions trackAllCaptures="true">
<add input="{QUERY_STRING}" pattern="(.*)(&?scope=.+&?)(.*)" />
</conditions>
<action type="Rewrite" url="google/redirect/url?{C:1}{C:3}" appendQueryString="false" />
</rule>
推荐阅读
- sql - 如果我的输入是 1 月,年份是 2016 年,那么它需要输入 01-jan-16 到 31-jan-16
- php - php没有使用jquery发送数据
- java - 如何为 .xlsx 格式的 Excel 注释插入背景图像(Apache POI XSSF)?
- oracle - TNS:侦听器当前不知道连接描述符中请求的服务
- javascript - 为什么我的 API 中的这个端点返回 [] 而不是 404 错误?
- ios - 动态更改静态表格视图单元格高度
- xamarin - CurrentCulture 自动重置 Xamarin Android
- haskell - 按键编辑 AssocList
- javascript - 更改包含特定字符串的 Jquery ui 自动完成结果
- amazon-web-services - User X not authorized to perform cloudformation:CreateChangeSet on resource arn:cloudformation:ap-xx-x:transform:Serverless-2016-10-31