全栈
文章平均质量分 60
全栈
CHNMSCS
分享是一种快乐,
脚踏实地,仰望星空
展开
-
Identity and Authentication - Sending Tokens with Requests
先给个简单代码来热热身from flask import Flask, requestapp = Flask(__name__)@app.route('/headers')def headers(): # unpack the request header print('hello world') return 'not implemented'在 Terminal里,对应的文件夹里,输入下面的命令$ export FLASK_APP=example.py$ ex原创 2022-01-17 06:48:00 · 1150 阅读 · 1 评论 -
Identity and Authentication - Local Storage
Local Storage is an implementation of a key-value store which is accessible through a javascript interface in most modern browsers. It is a general purpose interface to store strings which will persist in memory from session to session. It is designed for原创 2022-01-16 14:38:42 · 247 阅读 · 0 评论 -
Identity and Authentication - 验证 Autho0 Tokens (附代码)
如何使用jwt, 请点击这里查看如何使用 Authorization, 点击这里在这里,就放一个简单的代码import sysimport json# pip3 install python-josefrom jose import jwtfrom urllib.request import urlopen# Configuration# UPDATE THIS TO REFLECT YOUR AUTH0 ACCOUNTAUTH0_DOMAIN = 'YOUR_AUTH0_DOMAIN原创 2022-01-16 14:03:23 · 371 阅读 · 0 评论 -
Identity and Authentication - Generating and Verifying JWTs (附代码)
如果要了解 jwt, 点击这里简单代码实现import jwtimport base64# Init our Datapayload = { 'school':'example'}algo = 'HS256'secret = 'learning'# Encode a JWTencoded_jwt = jwt.encode(payload, secret, algorithm=algo)print(encoded_jwt)# Decode a JWTdecoded_jw原创 2022-01-16 13:05:00 · 2159 阅读 · 0 评论 -
Identity and Authentication - JSO Web Tokens (JWTs)
使用 JWTs 的好处:StatelessDifficult to FakePopular and easily implemented across platformsFlexbileParts of a JSON Web Tokenheader.payload.signatureIncluding Data in Our JWT Payload解释 Payload:{ "user":"usr", "school":"example", "role": "rle"}原创 2022-01-16 12:39:08 · 2664 阅读 · 0 评论 -
Identity and Authentication - Implementing Auth0 (实现Auth0)
点击这里,进入设置Auth0如果还没有账号,就sign up,创建一个账号。就按照下面的步骤来实现Autho0根据图片里的指示操作在 Settings 里创建 Application URIs其他选项,保持default setting, 在最后点击 save changesApplications 设置好之后,就得设置 APIs在 Setting里,保持default settings.用这个例子来判断,设置有没有成功复制 highlight 部分,到 C原创 2022-01-16 12:02:56 · 389 阅读 · 0 评论 -
Identity and Authentication - Implementing Auth0
第三方验证图The front-end interact with a third party service to provide the login screen, and perform the authentication. The software will direct our clients to a hosted page provided by Auth0. On this page, the user can perform one of many types of authenti原创 2022-01-16 08:28:06 · 193 阅读 · 0 评论 -
Identity and Authentication - Third Party Auth Systems
Third Party Auth SystemsMost of the risk lies in our back-end, where the user is making a request, our server is attempting to find our ground truth, and determining whether or not that user is who they say they are.MonolithicOften in monolithic serv原创 2022-01-16 07:56:03 · 312 阅读 · 0 评论 -
Identity and Authentication - Alternative Authentication Methods
Single Sign-on (SSO)The Single Sign-on or trusting someone else to answer the question who is making the request? Single Sign-on gives us a bunch of benefits. First, we don’t have to perform the actual authentication. We’re trusting that some engineers at原创 2022-01-16 07:36:58 · 225 阅读 · 0 评论 -
Identity and Authentication - Common Authentication Methods
Username and PasswordsThis is the most common method of identifying users in the age of Software as a Service (SaaS)解释上面的图中的步骤:Login Request:POST /loginpostuser = { username: 'users', password: 'pws'}Find users:SELECT * FROM database_exampleWH原创 2022-01-16 07:10:45 · 3447 阅读 · 0 评论 -
Identity and Authentication - 介绍
Token is a temporary credential that can be stored on our client and be sent along with each future request. When the server receives a token, we verify that token is valid, we can perform specific actions that might be sensitive and return a response to .原创 2022-01-16 06:52:03 · 225 阅读 · 0 评论 -
Identity and Access Management - python decorators (代码)
from functools import wraps def add_greeting(f): @wraps(f) def wrapper(*args, **kwargs): print("Hello!") return f(*args, **kwargs) return wrapper@add_greetingdef print_name(name): print(name)print_name('sandy')结果如下:原创 2022-01-07 09:18:19 · 491 阅读 · 1 评论 -
Identity and Access Management - 复习HTTP和Flask (代码)
文件结构example| example.py# example.pyfrom flask import Flask, request, jsonify, abort app = Flask(__name__)greetings = { 'en': 'hello', 'es': 'Hola', 'ar': 'مرحبا', 'ru': 'Привет', 'fi': 'Hei', 'he': 'שלום', 'ja': 'こんにち原创 2022-01-07 08:44:48 · 867 阅读 · 0 评论 -
Identity and Access Management - 介绍
原创 2022-01-07 07:57:08 · 339 阅读 · 0 评论 -
API Documentation - Project Documentation 介绍
Well-documented projects have a README.md file that should clearly explain the project and how to get started with it to any developers who may want to use or contribute to the project. Depending on your personal style preferences and project type, the str原创 2022-01-07 06:21:36 · 367 阅读 · 0 评论 -
API Documentation - 介绍
Good API Documentation:Good API documentation allows any developer considering the API to quickly understand the purpose of the API, the data it works with, and how to send requests and parse the responses. Some documentation, particularly for large proje原创 2022-01-07 06:11:13 · 1151 阅读 · 0 评论 -
API Testing - TDD Demo (附代码)
文件路劲example| models.py| test_flaskr.py|--flaskr| | __init__.py是在这篇基础上,添加代码,主要是在__init__.py 和 test_flaskr.py直接上代码:# __init__.py# 版权所有import osfrom flask import Flask, request, abort, jsonifyfrom flask_sqlalchemy import SQLAlchemy from fla原创 2022-01-06 12:57:31 · 223 阅读 · 0 评论 -
API Testing - TDD for APIs
Test-Driven Development (TDD) is a software development paradigm used very commonly in production. Often this is done via pair programming. It is based on a short, rapid development cycle in which tests are written before the executable code and constantly原创 2022-01-06 12:19:16 · 179 阅读 · 0 评论 -
Endpoints and Payloads - 实现对API的增删改查 CRUD (附代码)
文件结构:example| models.py|--flaskr| | __init__.py上代码# __init__.py# 版权所有import osfrom flask import Flask, request, abort, jsonifyfrom flask_sqlalchemy import SQLAlchemyfrom flask_cors import CORSimport randomfrom models import setup_db, Book原创 2022-01-06 11:55:52 · 416 阅读 · 0 评论 -
API Testing - Demo (附代码)
文件结构:example| models.py| test_flaskr.py|--flaskr| | __init__.py现在就上代码# models.py# 版权所有import osfrom sqlalchemy import Column, String, Integer, create_enginefrom flask_sqlalchemy import SQLAlchemyimport jsondatabase_name = "bookshelf_tes原创 2022-01-06 11:02:41 · 604 阅读 · 0 评论 -
API Testing - Testing in Flask介绍
# Import all dependenciesimport unittestimport jsonfrom flaskr import create_appfrom models import setup_db# Define Test Case Class# Class name should be intuitiveclass AppNameTestCase(unittest.TestCase): # setUp run before each test def setUp(原创 2022-01-06 08:22:20 · 194 阅读 · 0 评论 -
API Testing - 介绍
As with any code you write, you want to test your API to ensure that requests are processed as you expect, the responses sent are correct, and the operations performed on the database are correct and persist.Why Test an API?As with all tests, writing uni原创 2022-01-06 07:50:13 · 366 阅读 · 0 评论 -
Endpoints and Payloads - Flask Error Handling
Why we careabort() errors are not digestibleFor successful requests, we should be consistent and send back JSONClient will need clearer information about the exact error@app.errorhandler decorator usageTakes the status code or Python error as an ar原创 2022-01-05 17:57:27 · 216 阅读 · 2 评论 -
Endpoints and Payloads - Route decorator and pagination Example (有代码)
在上一篇博客里讲解了如何应用 route decorator 和 pagination, 点击这里查看现在就提供一些例子来做个demo文件结构:example| models.py|--flaskr| | __init__.py前提是,得在本地创建postgre数据库,可以查看如何创建数据库所使用的数据为:现在提供models.py# models.py# 版权所有import osfrom sqlalchemy import Column, String, Integ原创 2022-01-05 14:16:53 · 531 阅读 · 1 评论 -
Endpoints and Payloads - Flask_Route Decorator and Pagination in Flask
Flask Routes@app.route extensibilityBasic:Just includes path@app.route("/hello")def get_greeting(): return jsonify({'message':'Hello World!'})Extended:Variable Rules in the pathExample endpoint: http://www.example.com/entrees/1<variable_nam原创 2022-01-05 12:42:39 · 199 阅读 · 0 评论 -
Endpoints and Payloads - Flask_CORS
Installation安装命令$ pip3 install -U flask-corsInitializationOnce Flask-CORS is installed, you simply import the CORS function and call it with your app instance as a parameter. This will initialize Flask-CORS will all default optionsfrom flask_cors.原创 2022-01-05 09:53:49 · 157 阅读 · 2 评论 -
Endpoints and Payloads - CORS
Cross-Origin Resource Sharing (CORS)Two Main ComponentsSecurity and the Same-Origin Policy(This is a policy that says that a web browser allows scripts in one page to access data in another page but only if they have the same origin. This policy protec原创 2022-01-02 16:03:06 · 505 阅读 · 6 评论 -
Endpoints and Payloads - Organizing API endpoints
When organizing API endpoints, they should be based on the resources instead of on actions. The request methods will determine what action should be taken at a given URL endpoint. Your entire API’s scheme should be consistent, clear and concise.在这里说一下,什么原创 2022-01-02 15:33:18 · 132 阅读 · 0 评论 -
HTTP and Flask Basics - Introduction to Curl and Chrome Dev Tools
Chrome Dev ToolsIf you want to check how your requests are being sent, and what the responses are from the browser, you can do so using Chrome Dev Tools. There are numerous tools within it, but the key area you will use is the Network tab.CurlCurl is原创 2021-12-31 17:02:30 · 1023 阅读 · 0 评论 -
HTTP and Flask Basics - Intro to Flask
直接上代码# Import your dependenciesfrom flask import Flask, jsonify# test_config=None, 因为这个程序没有在test environmentdef create_app(test_config=None): # Create and configure the app # "name" basically just tells the application which directory it's hos原创 2021-12-31 16:36:14 · 102 阅读 · 0 评论 -
HTTP and Flask Basics - HTTP Responses
After the request has been received by the server and processed, the server returns an HTTP response message to the client. The response informs the client of the outcome of the requested operation.Elements:Status Code & Status MessageHTTP Version原创 2021-12-31 15:42:13 · 1241 阅读 · 2 评论 -
HTTP and Flask Basics - HTTP Requests
HTTP requests are sent from the client to the server to initiate some operation. In addition to the URL, HTTP requests have other elements to specify the requested resource.Elements:Method: Defines the operation to be performedPath: The URL of the reso原创 2021-12-31 11:59:42 · 646 阅读 · 1 评论 -
HTTP and Flask Basics -HTTP介绍
Hypertext Transfer Protocol (HTTP) is a protocol that provides a standardized way for computers to communicate with each other. It has been the foundation for data communication over the internet since 1990 and is integral to understanding how client-serve原创 2021-12-31 11:05:41 · 966 阅读 · 0 评论 -
Introduction to APIs - RESTful APIs
REST stands for Representational State Transfer.Here is a short summary of the REST principles:Uniform Interface: Every rest architecture must have a standardized way of accessing and processing data resources. This includes unique resource identifiers原创 2021-12-27 13:48:20 · 115 阅读 · 4 评论 -
Introduction to APIs - Internet Protocols
Internet Protocol (IP) is the protocol for sending data from one computer to another across the internet. Each computer must have a unique IP address that identifies it from all other computers connected to the internet.There are many other internet proto原创 2021-12-27 13:36:20 · 279 阅读 · 0 评论 -
Introduction to APIs - How APIs Work
举个例子:Client-Server CommunicationWhen you got to a bank, the bank teller acts as an intermediary or interface between you and the bank vault. And this is the same type of relationship we see in client-server communication: The user or client makes a reques原创 2021-12-27 13:04:48 · 330 阅读 · 0 评论 -
Introduction to APIs - What are APIs?
Application Programming Interface (APIs) are essential for exposing that backend in a controlled way, so you can define behaviors to access and manipulate data while maintaining its integrity.An API is an interface. It’s something that has been created to原创 2021-12-27 12:50:17 · 187 阅读 · 0 评论 -
Build a CRUD App with SQLAlchemy - Modeling a many-to-many in SQLAlchemy ORM
To set up a many-to-many in SQLAlchemy:Define an association table using Table from SQLAlchemySet the multiple foreign keys in the association tableMap the association table to a parent model using the option secondary in db.relationship# Setting up原创 2021-12-03 14:46:03 · 681 阅读 · 0 评论 -
Build a CRUD App with SQLAlchemy - One-to-Many Relationship
There are 3 types of relationships in relational database design:One-to-OneOne-to-Many (or Many-to-One)Many-to-ManyOne-to-OneA row in table A can have only one matching row in table B, and vice versa.This is not a common relationship type, as the原创 2021-12-03 13:11:46 · 239 阅读 · 0 评论 -
Build a CRUD App with SQLAlchemy - Foreign Key Constraint Setup
db.relationshipAllows SQLAlchemy to identify relationships between modelsLinks relationships with backrefs (child1.some_parent)Configures relationship dynamics between parents and childrendb.relationship does not set up foreign key constraints for you原创 2021-11-26 15:54:59 · 110 阅读 · 0 评论