首先,我对Keycloak非常陌生,请问如果我要问的问题可能是错的。
我已经安装了Keycloak服务器,并且可以使用以下命令访问Web UI:
我的要求是通过将领域用户传递给k Keycloak API来验证领域用户,并从那里获取令牌作为响应,然后将该令牌传递给我的其他Web API调用。
但是我找不到关于如何执行此操作的简单指南...
更新:
从使用UI KEYCLOAK:
到目前为止:
我能够创建一个realm:例如:DemoRealm
在Realm我创建的客户端下:例如:DemoClient
在客户端下,我创建了用户:例如: DemoUser
使用方法POSTMAN:
我也能够成功使用获取令牌
http://localhost:8080/auth/realms/DemoRelam/protocol/openid-connect/token
POST:
{
"grant_type": "client_credentials",
"username": "",
"password": "",
"client_secret":"",
"client_id":"DemoClient"
}
Run Code Online (Sandbox Code Playgroud)
作为回应,我得到了令牌。
{
"access_token": "eyJhbGciOiJSUzI1NiIsINVSHGhepnDu13SwRBL-v-y-04_6e6IJbMzreZwPI-epwdVPQe-ENhpvms2WdGM_DmgMLZ8YQFS4LDl9R7ZHT8AgXe-WCFV6OFkA7zvdeFwQ4kVVZE0HlNgHgoi4DrgMfwwz_ku1yJNJP3ztTY1nEqmA",
"expires_in": 300,
"refresh_expires_in": 1800,
"refresh_token": "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJRRnB5YlloMGVEektIdlhOb3JvaFUxdlRvWVdjdP3vbfvk7O0zvppK9N4-oaUqZSr0smHv5LkuLDQYdPuxA",
"token_type": "bearer",
"not-before-policy": 0,
"session_state": "bb1c586a-e880-4b96-ac16-30e42c0f46dc"
}
Run Code Online (Sandbox Code Playgroud)
此外,我深入研究了更多细节,并找到了此API指南:
http://www.keycloak.org/docs-api/3.0/rest-api/index.html#_users_resource
在本指南中,提到了可以使用“获取用户”来获取领域的用户返回用户列表,并根据查询参数进行过滤
GET /admin/realms/{realm}/users
Run Code Online (Sandbox Code Playgroud)
但是,当我POSTMAN用来获取用户时,我得到了403错误代码。我正在传递与在上一步中获得的身份验证相同的令牌。
http://localhost:8080/auth/admin/realms/DemoRelam/users
Run Code Online (Sandbox Code Playgroud)
谁能指导我?
假设我们有一个联合类型,它表示三个不同字符串值之一。
type Animal = 'bird' | 'cat' | 'dog';
Run Code Online (Sandbox Code Playgroud)
现在我想创建一只狗,并检查它是什么类型的动物,以产生它执行的正确噪音。
let oscar: Animal = 'dog';
switch (oscar) {
case 'bird':
console.log('tweet');
break;
case 'cat':
console.log('meow');
break;
case 'dog':
console.log('bark');
break;
}
Run Code Online (Sandbox Code Playgroud)
此代码将导致 TypeScript 错误:(Type '"bird"' is not comparable to type '"dog"'.ts(2678)与 cat 类似)。但是,如果我对变量使用显式类型转换oscar,则它可以正常工作:
switch (oscar as Animal) {
case 'bird':
...
case 'cat':
...
case 'dog':
...
}
Run Code Online (Sandbox Code Playgroud)
您能否向我解释一下,如果我使用显式值 for ,为什么前两个 switch 语句会失败oscar?
如果我将 Oscar 声明为常量:const oscar = 'dog';,我可以理解该错误,因为在这种情况下,它始终是一只狗,而不是其他任何东西。然而,想象一下,如果巫师执行某个咒语,奥斯卡就会变成一只猫:
let oscar: Animal …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过 Python(Jupyter Notebooks)连接到 HIVE。我已经安装了使用 Python 连接 HIVE 所需的所有软件包 -
sasl 0.2.1 py37h8a4fda4_1
thrift 0.13.0 pypi_0 pypi
thrift-sasl 0.3.0 pypi_0 pypi
pyhive 0.6.1 pypi_0 pypi
from pyhive import hive
conn = hive.Connection(host="xxxxxxx", port=xxxxx, username="xxxxxxxx")
Run Code Online (Sandbox Code Playgroud)
但无法连接,因为它抛出错误:TTransportException: Could not start SASL: b'Error in sasl_client_start (-4) SASL(-4): no mechanism available: Unable to find a callback: 2'。
我错过了什么吗?如何连接?
目前我偶然发现了 Angular的ContentChildren 装饰器。在第一个代码示例中,使用了以下语法:
import {AfterContentInit, ContentChildren, Directive, QueryList} from '@angular/core';
@Directive({selector: 'child-directive'})
class ChildDirective {
}
@Directive({selector: 'someDir'})
class SomeDir implements AfterContentInit {
@ContentChildren(ChildDirective) contentChildren !: QueryList<ChildDirective>; // this line is relevant
ngAfterContentInit() {
// contentChildren is set
}
}
Run Code Online (Sandbox Code Playgroud)
请注意在变量定义之后紧跟一个冒号的感叹号@ContentChildren(ChildDirective) contentChildren。在此 StackOverflow 线程中,我发现在访问变量或对象属性时,此语法可用作“非空断言运算符”。
我现在的问题是类型定义之前的感叹号是否与正常上下文中的含义完全相同。它是简单地告诉 TypeScript 编译器:“好吧,不用担心null或未定义”,或者这种语法在这种情况下是否有其他特定含义?
我想在打字稿中使用<script setup>带有 props 类型检查的功能。但似乎<script setup>没有将 RouteRecordRaw 作为类型导入,而是作为值导入?如果我在 vite 中运行此代码,浏览器控制台将打印错误:
“未捕获的语法错误:请求的模块'/node_modules/.vite/vue-router.js?v=52a879a7'不提供名为'RouteRecordRaw'的导出”
代码:
<script lang="ts" setup>
import { RouteRecordRaw } from "vue-router";
// VSCode will print an error: "RouteRecordRaw" only refers to a type, butisbeing used as a value here. (TS2693)
import { defineProps } from "vue";
const props = defineProps<{
routeList: Array<RouteRecordRaw>;
}>();
const renderRoutes = props.routeList;
</script>
Run Code Online (Sandbox Code Playgroud) 我想使用 Keycloak 来保护我的路线,Keycloak 是一种开源身份和访问管理。我试图遵循他们的文档,但我无法使其正常工作。
这是我的 app.js 文件:
const express = require( 'express' );
const routePlaces = require( './routes/placesRoutes' );
const Keycloak = require( 'keycloak-connect' );
const session = require( 'express-session' );
const memoryStrore = new session.MemoryStore();
let kcConfig = {
clientId = 'parking-app',
bearerOnly: true,
serverUrl: 'localhost:8080/auth',
realm: 'FlexParking',
reamlPublicKey: 'MIIBIjANBg…'
}
var keycloak = new KeyCloak( {store: memoryStore}, kcConfig );
app.use( keycloak.middleware({
// here I think I have to place my routes
}));
app.use( '/places, routePlaces );
module.exports = …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 REDUX 模式构建我的下一个 Angular 应用程序,但由于某种原因我无法导入所需的库。
node_modules/@ngrx/store/src/models.d.ts(58,58) 中的错误:错误 TS2304:找不到名称“未知”。
node_modules/@ngrx/store/src/models.d.ts(58,82):错误 TS2370:剩余参数必须是数组类型。
node_modules/@ngrx/store/src/models.d.ts(59,52):错误 TS2370:剩余参数必须是数组类型。
node_modules/@ngrx/store/src/models.d.ts(59,73):错误 TS2304:找不到名称“未知”。
包.json
{
"name": "ng6-proj",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.1.0",
"@angular/cdk": "^6.2.0",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/material": "^6.4.7",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"@ngrx/store": "^8.6.0",
"core-js": "^2.5.4",
"hammerjs": "^2.0.8",
"rxjs": "~6.2.0",
"zone.js": "~0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": …Run Code Online (Sandbox Code Playgroud) 我想通过一个简单的 Nginx 服务器来提供 Angular 8 应用程序。不幸的是,当我尝试提供该应用程序时,我在 Chrome 中收到以下错误:
无法加载模块脚本:服务器以非 JavaScript MIME 类型“text/plain”进行响应。根据 HTML 规范对模块脚本强制执行严格的 MIME 类型检查。
我找到了几个解决方案(例如这个和那个)建议我应该手动配置所有script标签并添加type="javascript". 但是,就我而言,我无法执行此操作,因为我的应用程序包含只能在脚本类型属性为 时加载的Web 组件type="module"。
我的 Nginx 配置如下所示:
events { worker_connections 1024; }
http
{
sendfile on;
server {
root /usr/share/nginx/html/app;
listen 9020;
server_name localhost;
location / {
index index.html index.htm;
}
location ~ \.css {
add_header Content-Type text/css;
}
location ~ \.js {
add_header Content-Type application/javascript;
}
}
}
Run Code Online (Sandbox Code Playgroud)
你知道我如何配置 Angular 或 Nginx …
我有一个 wagtail 项目,根目录有一个“主页”(slug='home')。
第二页“博客”是“主页”的子页面(slug='blog')。
最后,我有博客发布页面,它们是“博客”的子页面(slug='blog-post-1' 等)。
在blog/models.py我有以下代码:
class BlogListingPage(Page):
"""List the Blog detail pages."""
template = "blog/blog_listing_page.html"
....
def get_context(self, request, *args, **kwargs):
"""Add custom content to our context."""
context = super().get_context(request, *args, **kwargs)
context['blog_pages'] = self.get_children().live()
return context
class BlogDetailPage(Page):
"""Blog detail page."""
template = "blog/blog_detail_page.html"
....
Run Code Online (Sandbox Code Playgroud)
要访问我使用的博客:
<a class="nav-link" href="/blog">Blog</a>
Run Code Online (Sandbox Code Playgroud)
这非常有效。
现在,详细信息页面的 URL 是/home/blog/blog-post-1/等,但该页面实际上位于/blog/blog-post-1/.
'/home' 来自哪里,我该如何摆脱它?
angular ×3
typescript ×3
keycloak ×2
ecmascript-6 ×1
hive ×1
java ×1
javascript ×1
nginx ×1
ngrx ×1
node.js ×1
python ×1
python-3.x ×1
rxjs ×1
server ×1
union-types ×1
vite ×1
vuejs3 ×1
wagtail ×1