Commit 8c29339f1364a066553db06444933cd4c0975f51
1 parent
ff4ca5a7
Add support for port in oauth2 domain name. Update proxy.conf to support oauth2 urls
Showing
4 changed files
with
27 additions
and
2 deletions
... | ... | @@ -40,7 +40,7 @@ public class OAuth2Controller extends BaseController { |
40 | 40 | @ResponseBody |
41 | 41 | public List<OAuth2ClientInfo> getOAuth2Clients(HttpServletRequest request) throws ThingsboardException { |
42 | 42 | try { |
43 | - return oAuth2Service.getOAuth2Clients(MiscUtils.getScheme(request), MiscUtils.getDomainName(request)); | |
43 | + return oAuth2Service.getOAuth2Clients(MiscUtils.getScheme(request), MiscUtils.getDomainNameAndPort(request)); | |
44 | 44 | } catch (Exception e) { |
45 | 45 | throw handleException(e); |
46 | 46 | } | ... | ... |
... | ... | @@ -68,6 +68,22 @@ public class MiscUtils { |
68 | 68 | return request.getServerName(); |
69 | 69 | } |
70 | 70 | |
71 | + public static String getDomainNameAndPort(HttpServletRequest request){ | |
72 | + String domainName = getDomainName(request); | |
73 | + String scheme = getScheme(request); | |
74 | + int port = MiscUtils.getPort(request); | |
75 | + if (needsPort(scheme, port)) { | |
76 | + domainName += ":" + port; | |
77 | + } | |
78 | + return domainName; | |
79 | + } | |
80 | + | |
81 | + private static boolean needsPort(String scheme, int port) { | |
82 | + boolean isHttpDefault = "http".equals(scheme.toLowerCase()) && port == 80; | |
83 | + boolean isHttpsDefault = "https".equals(scheme.toLowerCase()) && port == 443; | |
84 | + return !isHttpDefault && !isHttpsDefault; | |
85 | + } | |
86 | + | |
71 | 87 | public static int getPort(HttpServletRequest request){ |
72 | 88 | String forwardedProto = request.getHeader("x-forwarded-proto"); |
73 | 89 | ... | ... |
... | ... | @@ -27,6 +27,14 @@ const PROXY_CONFIG = { |
27 | 27 | "target": ruleNodeUiforwardUrl, |
28 | 28 | "secure": false, |
29 | 29 | }, |
30 | + "/oauth2": { | |
31 | + "target": forwardUrl, | |
32 | + "secure": false, | |
33 | + }, | |
34 | + "/login/oauth2": { | |
35 | + "target": forwardUrl, | |
36 | + "secure": false, | |
37 | + }, | |
30 | 38 | "/static": { |
31 | 39 | "target": forwardUrl, |
32 | 40 | "secure": false, | ... | ... |
... | ... | @@ -52,6 +52,7 @@ import { OAuth2Service } from '@core/http/oauth2.service'; |
52 | 52 | export class OAuth2SettingsComponent extends PageComponent implements OnInit, HasConfirmForm, OnDestroy { |
53 | 53 | |
54 | 54 | private URL_REGEXP = /^[A-Za-z][A-Za-z\d.+-]*:\/*(?:\w+(?::\w+)?@)?[^\s/]+(?::\d+)?(?:\/[\w#!:.,?+=&%@\-/]*)?$/; |
55 | + private DOMAIN_AND_PORT_REGEXP = /^(?:\w+(?::\w+)?@)?[^\s/]+(?::\d+)?$/; | |
55 | 56 | private subscriptions: Subscription[] = []; |
56 | 57 | private templates = new Map<string, OAuth2ClientRegistrationTemplate>(); |
57 | 58 | private defaultProvider = { |
... | ... | @@ -233,7 +234,7 @@ export class OAuth2SettingsComponent extends PageComponent implements OnInit, Ha |
233 | 234 | const domain = this.fb.group({ |
234 | 235 | name: [domainInfo ? domainInfo.name : this.window.location.hostname, [ |
235 | 236 | Validators.required, |
236 | - Validators.pattern('((?![:/]).)*$')]], | |
237 | + Validators.pattern(this.DOMAIN_AND_PORT_REGEXP)]], | |
237 | 238 | scheme: [domainInfo?.scheme ? domainInfo.scheme : DomainSchema.HTTPS, Validators.required] |
238 | 239 | }, {validators: this.uniqueDomainValidator}); |
239 | 240 | return domain; | ... | ... |