Skip to content

Commit b6938df

Browse files
committed
Make custom provider the default.
Closes #93.
1 parent 7036353 commit b6938df

1 file changed

Lines changed: 37 additions & 68 deletions

File tree

popup-app/components/IdpSelect.js

Lines changed: 37 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,26 @@ import { ipcStorage, getData } from '../../src/storage'
66

77
import './IdpSelect.css'
88

9-
class IdpSelect extends React.Component {
10-
state = {
11-
enteringCustomIdp: false,
12-
customIdp: { url: '' },
13-
error: null
14-
}
15-
16-
toggleEnteringCustomIdp = () =>
17-
this.setState(currentState => ({
18-
enteringCustomIdp: !currentState.enteringCustomIdp
19-
}))
9+
export default class IdpSelect extends React.Component {
10+
state = { idp: '', error: null }
2011

2112
handleChangeIdp = event => {
22-
let url = event.target.value
13+
let idp = event.target.value
2314
// Auto-prepend https: if the user is not typing it
24-
if (!/^($|h$|ht)/.test(url)) url = `https://${url}`
25-
this.setState({ customIdp: { url } })
15+
if (!/^($|h$|ht)/.test(idp)) idp = `https://${idp}`
16+
this.setState({ idp })
2617
}
2718

2819
handleBlurIdp = event => {
29-
let url = event.target.value
20+
let idp = event.target.value
3021
// Auto-prepend https: if not present
31-
if (!/^(https?:\/\/|$)/.test(url))
32-
url = url.replace(/^([a-z]*:\/*)?/, 'https://')
33-
this.setState({ customIdp: { url } })
22+
if (!/^(https?:\/\/|$)/.test(idp))
23+
idp = idp.replace(/^([a-z]*:\/*)?/, 'https://')
24+
this.setState({ idp })
3425
}
3526

36-
handleSelectIdp = idp => async event => {
37-
event.preventDefault()
27+
handleSelectIdp = async idp => {
28+
this.setState({ idp })
3829
if (!window.opener) {
3930
console.warn('No parent window')
4031
this.setState({
@@ -48,7 +39,7 @@ class IdpSelect extends React.Component {
4839
...(await this.getClient().request('getLoginOptions')),
4940
storage: this.getStorage()
5041
}
51-
await auth.login(idp.url, loginOptions)
42+
await auth.login(idp, loginOptions)
5243
}
5344

5445
getClient() {
@@ -62,69 +53,47 @@ class IdpSelect extends React.Component {
6253
async componentDidMount() {
6354
const { rpConfig } = await getData(this.getStorage())
6455
if (rpConfig) {
65-
this.setState({ customIdp: { url: rpConfig.provider.url } })
66-
}
67-
}
68-
69-
componentDidUpdate() {
70-
if (this.idpInput) {
71-
this.idpInput.focus()
56+
this.setState({ idp: rpConfig.provider.url })
7257
}
58+
this.idpInput.focus()
7359
}
7460

7561
render() {
7662
const { appName, idps } = this.props
77-
const { customIdp, enteringCustomIdp, error } = this.state
63+
const { idp, error } = this.state
7864
return (
7965
<div>
8066
<h1>
8167
Log in to <span className="app-name">{appName}</span>
8268
</h1>
83-
{error && <Error error={error} />}
84-
<p>Choose where you log in</p>
85-
{enteringCustomIdp && (
86-
<form
87-
className="custom-idp"
88-
onSubmit={this.handleSelectIdp(customIdp)}
89-
>
90-
<input
91-
ref={input => (this.idpInput = input)}
92-
type="url"
93-
placeholder="https://my-identity.provider"
94-
value={customIdp.url}
95-
onChange={this.handleChangeIdp}
96-
onBlur={this.handleBlurIdp}
97-
/>
98-
<button type="submit">Log In</button>
99-
<button type="reset" onClick={this.toggleEnteringCustomIdp}>
100-
Cancel
101-
</button>
102-
</form>
103-
)}
104-
<div className="idp-list">
105-
<Idp
106-
idp={{ displayName: 'custom provider' }}
107-
handleSelectIdp={this.toggleEnteringCustomIdp}
69+
{error && <p className="error">{error}</p>}
70+
<p>Please enter your WebID or the URL of your identity provider:</p>
71+
<form className="custom-idp" onSubmit={() => this.handleSelectIdp(idp)}>
72+
<input
73+
ref={input => (this.idpInput = input)}
74+
type="url"
75+
placeholder="https://my-identity.provider"
76+
value={idp}
77+
onChange={this.handleChangeIdp}
78+
onBlur={this.handleBlurIdp}
10879
/>
80+
<button type="submit" disabled={!idp}>
81+
Go
82+
</button>
83+
</form>
84+
<p>Or pick an identity provider from the list below:</p>
85+
<div className="idp-list">
10986
{idps.map(idp => (
110-
<Idp
111-
idp={idp}
112-
handleSelectIdp={this.handleSelectIdp(idp)}
87+
<button
88+
className="idp"
89+
onClick={() => this.handleSelectIdp(idp.url)}
11390
key={idp.url}
114-
/>
91+
>
92+
{idp.displayName}
93+
</button>
11594
))}
11695
</div>
11796
</div>
11897
)
11998
}
12099
}
121-
122-
const Idp = ({ idp, handleSelectIdp }) => (
123-
<button className="idp" onClick={handleSelectIdp}>
124-
{idp.displayName}
125-
</button>
126-
)
127-
128-
const Error = ({ error }) => <p className="error">{error}</p>
129-
130-
export default IdpSelect

0 commit comments

Comments
 (0)