This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
authorize.jsx
167 lines (148 loc) · 5.32 KB
/
authorize.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import PropTypes from 'prop-types';
import React from 'react';
import {FormattedHTMLMessage, FormattedMessage} from 'react-intl';
import {allowOAuth2, getOAuthAppInfo} from 'actions/admin_actions.jsx';
import icon50 from 'images/icon50x50.png';
import FormError from 'components/form_error.jsx';
export default class Authorize extends React.Component {
static get propTypes() {
return {
location: PropTypes.object.isRequired,
params: PropTypes.object.isRequired
};
}
constructor(props) {
super(props);
this.handleAllow = this.handleAllow.bind(this);
this.handleDeny = this.handleDeny.bind(this);
this.state = {};
}
componentWillMount() {
const clientId = this.props.location.query.client_id;
if (!(/^[a-z0-9]+$/.test(clientId))) {
return;
}
getOAuthAppInfo(
clientId,
(app) => {
this.setState({app});
}
);
}
componentDidMount() {
// if we get to this point remove the antiClickjack blocker
const blocker = document.getElementById('antiClickjack');
if (blocker) {
blocker.parentNode.removeChild(blocker);
}
}
handleAllow() {
const params = this.props.location.query;
allowOAuth2(params,
(data) => {
if (data.redirect) {
window.location.href = data.redirect;
}
},
(err) => {
this.setState({error: err.message});
}
);
}
handleDeny() {
const redirectUri = this.props.location.query.redirect_uri;
if (redirectUri.startsWith('https://') || redirectUri.startsWith('http:https://')) {
window.location.replace(redirectUri + '?error=access_denied');
return;
}
window.location.replace('/error');
}
render() {
const app = this.state.app;
if (!app) {
return null;
}
let icon;
if (app.icon_url) {
icon = app.icon_url;
} else {
icon = icon50;
}
let error;
if (this.state.error) {
error = (
<div className='prompt__error form-group'>
<FormError error={this.state.error}/>
</div>
);
}
return (
<div className='container-fluid'>
<div className='prompt'>
<div className='prompt__heading'>
<div className='prompt__app-icon'>
<img
src={icon}
width='50'
height='50'
alt=''
/>
</div>
<div className='text'>
<FormattedHTMLMessage
id='authorize.title'
defaultMessage='<strong>{appName}</strong> would like to connect to your <strong>Mattermost</strong> user account'
values={{
appName: app.name
}}
/>
</div>
</div>
<p>
<FormattedHTMLMessage
id='authorize.app'
defaultMessage='The app <strong>{appName}</strong> would like the ability to access and modify your basic information.'
values={{
appName: app.name
}}
/>
</p>
<h2 className='prompt__allow'>
<FormattedHTMLMessage
id='authorize.access'
defaultMessage='Allow <strong>{appName}</strong> access?'
values={{
appName: app.name
}}
/>
</h2>
<div className='prompt__buttons'>
<button
type='submit'
className='btn btn-link authorize-btn'
onClick={this.handleDeny}
>
<FormattedMessage
id='authorize.deny'
defaultMessage='Deny'
/>
</button>
<button
type='submit'
className='btn btn-primary authorize-btn'
onClick={this.handleAllow}
>
<FormattedMessage
id='authorize.allow'
defaultMessage='Allow'
/>
</button>
</div>
{error}
</div>
</div>
);
}
}