我正在尝试理解 javascript 中的 mixin 以及到目前为止我读过的所有示例和文章都讨论添加方法而不是属性。
我发现Alex Jover Morales 的文章非常有用,我稍微修改了他的示例,在此处的 mixin 中包含了一个额外的 mixin 和具有新属性的构造函数。
我在下面所做的事情是反模式吗?mixin 中的构造函数和属性有问题吗?在每个 mixin 的构造函数中调用 super() 是否存在问题?
const PlayMixin = superclass => class extends superclass {
constructor(args) {
let { favouriteGame } = args
super(args);
this.favouriteGame=favouriteGame;
}
play() {
console.log(`${this.name} is playing ${this.favouriteGame}`);
}
};
const FoodMixin = superclass => class extends superclass {
constructor(args) {
let { genericFood } = args
super(args);
this.genericFood=genericFood;
}
eat() {
console.log(`${this.name} is eating ${this.genericFood}`);
}
poop() {
console.log("Going to …Run Code Online (Sandbox Code Playgroud)关于oAuth的一些教程使用Flask会话来存储状态参数并访问烧瓶会话中的令牌.(Brendan McCollam来自Pycon的非常有用的演示就是一个例子)
我知道Flask会在客户端将cookie存储在cookie中并且它们很容易暴露(参见Michael Grinberg的how-secure-is-the-flask-user-session).我自己尝试了这个,并且能够看到令牌到期等.
将状态和标记存储在烧瓶会话中是正确的还是应该存储在其他地方?
代码示例:
@app.route('/login', methods=['GET'])
def login():
provider = OAuth2Session(
client_id=CONFIG['client_id'],
scope=CONFIG['scope'],
redirect_uri=CONFIG['redirect_uri'])
url, state = provider.authorization_url(CONFIG['auth_url'])
session['oauth2_state'] = state
return redirect(url)
@app.route('/callback', methods=['GET'])
def callback():
provider = OAuth2Session(CONFIG['client_id'],
redirect_uri=CONFIG['redirect_uri'],
state=session['oauth2_state'])
token_response = provider.fetch_token(
token_url=CONFIG['token_url'],
client_secret=CONFIG['client_secret'],
authorization_response=request.url)
session['access_token'] = token_response['access_token']
session['access_token_expires'] = token_response['expires_at']
transfers = provider.get('https://transfer.api.globusonline.org/v0.10/task_list?limit=1')
return redirect(url_for('index'))
@app.route('/')
def index():
if 'access_token' not in session:
return redirect(url_for('login'))
transfers = requests.get('https://transfer.api.globusonline.org/v0.10/task_list?limit=1',
headers={'Authorization': 'Bearer ' + session['access_token']})
return render_template('index.html.jinja2',
transfers=transfers.json())
Run Code Online (Sandbox Code Playgroud) 我有这个组件从api检索帖子,但每次用户按下后退按钮时,都会触发componentDidMount事件并重复api调用.
反应或反应路由器是否提供了检测后退按钮被按下的方法,以便我可以阻止api呼叫?
import React, { Component } from 'react'
import { fetchData } from '../actions/actions'
import { connect } from 'react-redux'
import { receivePosts } from '../actions/actions'
import { PostList } from '../components/PostList'
import { withRouter } from 'react-router-dom'
class PostListContainer extends Component {
componentDidMount() {
this.props.fetchData("posts", receivePosts)
}
render() {
const { posts, active} = this.props
return (
<PostList
posts={active === '' ? posts : posts.filter( p => p.category === active)}
/>
)}
}
function mapStateToProps (state) {
return …Run Code Online (Sandbox Code Playgroud) 在这个小提琴https://jsfiddle.net/8279akmL/11/中,我试图将“ test”元素绑定到名为currentPlaceViewModel中可观察到的变量。我正在使用以下敲除语句:
ko.applyBindingsToNode(document.getElementById("test"),{text: currentPlace().name});
Run Code Online (Sandbox Code Playgroud)
但是,div绑定到列表项locations[0](绑定时currentPlace指向的项)而不是列表currentPlace本身。
当我更新currentPlace以指向其他列表项时locations[1],div不会更新。
在示例中,div当我更改时,唯一的更新是将其locations[0]更改为“ FOOBAR”。
如何将'div'绑定到currentPlace而不是locations[0]。
背景
我正在查看 OAuth 2.0 隐式授权流程,其中用户被重定向到身份验证服务,并且 JWT 令牌被发送回单页应用程序 (SPA)。令牌存储在 cookie 或本地存储中,在我看到的示例中,应用程序将根据是否可以在存储中找到令牌来隐藏/显示某些页面。
问题
问题是,在所有示例(来自服务提供商的官方示例)中,我能够手动将任何随机但格式正确的令牌添加到浏览器的本地存储中,并访问“安全”页面。
有人向我解释说,您无法在 SPA 中验证令牌,因为这需要暴露客户端机密,并且您应该在 API 服务器上验证令牌。这意味着您可以“隐藏”页面,但如果有人愿意,也很容易看到它们。话虽如此,您不太可能造成任何真正的损害,因为任何数据检索或操作都需要通过 API 服务器,并且应该在那里验证令牌。
这并不是真正的漏洞,但我看到的文档和示例并没有明确涵盖这种细微差别,我认为它可能会导致天真的程序员(比如我自己)认为某些页面是完全安全的,但实际上情况并非如此。
问题
如果有比我更了解情况的人确认这确实是 SPA 身份验证的工作原理,我将不胜感激。
oauth-2.0 ×2
reactjs ×2
access-token ×1
auth0 ×1
flask ×1
javascript ×1
knockout.js ×1
mixins ×1
react-router ×1
session ×1