我正在尝试在我的应用程序中设置Okta-React。它通过Okta-signin-widget成功进行了身份验证。但是,在每次页面加载时,它将至少向/authorize
调用4个HTTP请求:
Link to the GitHub of the django-windows-tools
对于每个这些请求,似乎都向DOM附加了一个iframe。 这是我的小部件和Okta-React的React代码:
Root.js
<Provider store={store}>
<Router>
<Security
issuer="https://dev-xxxx.oktapreview.com/oauth2/default"
client_id="xxxx"
redirect_uri={redirectUri}
onAuthRequired={customAuthHandler}
>
<App />
</Security>
</Router>
</Provider>
App.js
import React from 'react';
class App extends React.Component {
render() {
return (
<div className="fill">
<SecureRoute path="/test" component={Test} />
<Route
path="/signin"
render={({ location, history }) => (
<Signin location={location} history={history} {...this.props} />
)}
/>
<Route path="/implicit/callback" render={() => <ImplicitCallback />} />
</div>
);
}
}
使用Router(App)导出默认值
Signin.js
import React from 'react';
import ReactDOM from 'react-dom';
import { Redirect } from 'react-router-dom';
import OktaSignIn from '@okta/okta-signin-widget';
import '@okta/okta-signin-widget/dist/css/okta-sign-in.min.css';
import '@okta/okta-signin-widget/dist/css/okta-theme.css';
import { withAuth } from '@okta/okta-react';
class OktaSignInWidget extends React.Component {
constructor(props) {
super(props);
this.onSuccess = this.onSuccess.bind(this);
}
componentDidMount() {
const el = ReactDOM.findDOMNode(this);
this.widget = new OktaSignIn({
baseUrl: this.props.baseUrl,
authParams: {
display: 'page',
responseType: ['id_token', 'token'],
scopes: ['openid', 'groups', 'profile']
}
});
this.widget.renderEl({ el }, this.onSuccess, this.props.onError);
}
onSuccess(res) {
this.props.onSuccess(res);
this.widget.remove();
}
render() {
return <div />;
}
}
export default withAuth(
class Signin extends React.Component {
constructor(props) {
super(props);
this.state = {
authenticated: null
};
this.onSuccess = this.onSuccess.bind(this);
this.onError = this.onError.bind(this);
this.checkAuthentication = this.checkAuthentication.bind(this);
this.checkAuthentication();
}
componentDidUpdate() {
this.checkAuthentication();
}
async checkAuthentication() {
const authenticated = await this.props.auth.isAuthenticated();
if (authenticated !== this.state.authenticated) {
this.setState({ authenticated });
}
}
onSuccess = res => {
this.props.auth.redirect({
sessionToken: res.sessionToken || res.session.token
});
};
onError = error => {
console.log('Something went wrong', error);
};
render() {
if (this.state.authenticated === null) return null;
if (this.state.authenticated) {
return <Redirect to={{ pathname: '/test' }} />;
}
return (
<OktaSignInWidget
baseUrl="https://dev-xxxx.oktapreview.com"
onSuccess={this.onSuccess}
onError={this.onError}
/>
);
}
}
);
我正在使用:
"@okta/okta-auth-js": "^2.0.0",
"@okta/okta-react": "^1.0.3",
"@okta/okta-signin-widget": "^2.10.0",
"react-router-dom": "^4.3.1",
"react": "^16.4.2",
在将您的应用程序与Okta-React集成时,有没有人看到过类似的东西?这是预期的行为吗?我以为Okta只需要执行这些请求之一?
答案 0 :(得分:2)
@okta/okta-auth-js@2.0.0
中存在一个导致许多令牌刷新的错误,如果将该依赖关系升级到2.0.1
,则应该可以解决该问题。