// Copyright (c) 2015 Mattermost, Inc. All Rights Reserved. // See License.txt for license information. import FormError from 'components/form_error.jsx'; import {FormattedMessage, FormattedHTMLMessage} from 'react-intl'; import React from 'react'; import icon50 from 'images/icon50x50.png'; import {getOAuthAppInfo, allowOAuth2} from 'actions/admin_actions.jsx'; export default class Authorize extends React.Component { static get propTypes() { return { location: React.PropTypes.object.isRequired, params: React.PropTypes.object.isRequired }; } constructor(props) { super(props); this.handleAllow = this.handleAllow.bind(this); this.handleDeny = this.handleDeny.bind(this); this.state = {}; } componentWillMount() { getOAuthAppInfo( this.props.location.query.client_id, (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() { window.location.replace(this.props.location.query.redirect_uri + '?error=access_denied'); } 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 = (
); } return (

{error}
); } }