Skip to content

Commit f491a61

Browse files
committed
Auto-prepend https:// to custom IDP.
1 parent 29e98f1 commit f491a61

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

popup-app/components/IdpSelect.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,18 @@ class IdpSelect extends React.Component {
2020
}))
2121

2222
handleChangeIdp = event => {
23-
this.setState({ customIdp: { url: event.target.value } })
23+
let url = event.target.value
24+
// Auto-prepend https: if the user is not typing it
25+
if (!/^($|h$|ht)/.test(url)) url = `https://${url}`
26+
this.setState({ customIdp: { url } })
27+
}
28+
29+
handleBlurIdp = event => {
30+
let url = event.target.value
31+
// Auto-prepend https: if not present
32+
if (!/^(https?:\/\/|$)/.test(url))
33+
url = url.replace(/^([a-z]*:\/*)?/, 'https://')
34+
this.setState({ customIdp: { url } })
2435
}
2536

2637
handleSelectIdp = idp => async event => {
@@ -67,9 +78,10 @@ class IdpSelect extends React.Component {
6778
<input
6879
ref={input => (this.idpInput = input)}
6980
type="url"
70-
placeholder="https://my-identity.databox.me/profile/card#me"
81+
placeholder="https://my-identity.provider"
7182
value={customIdp.url}
7283
onChange={this.handleChangeIdp}
84+
onBlur={this.handleBlurIdp}
7385
/>
7486
<button type="submit">Log In</button>
7587
<button type="reset" onClick={this.toggleEnteringCustomIdp}>

0 commit comments

Comments
 (0)