小编Spa*_*ain的帖子

KeyCloak用户验证和获取令牌

首先,我对Keycloak非常陌生,请问如果我要问的问题可能是错的。

我已经安装了Keycloak服务器,并且可以使用以下命令访问Web UI:

http:// localhost:8008 / auth

我的要求是通过将领域用户传递给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)

谁能指导我?

java keycloak keycloak-services

7
推荐指数
2
解决办法
8269
查看次数

union类型的变量导致switch语句出错

假设我们有一个联合类型,它表示三个不同字符串值之一。

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)

javascript switch-statement typescript union-types

7
推荐指数
1
解决办法
4597
查看次数

错误 - b'sasl_client_start (-4) SASL(-4) 中的错误:无可用机制:无法找到回调:2'

我正在尝试通过 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'

我错过了什么吗?如何连接?

python hive python-3.x

7
推荐指数
1
解决办法
2521
查看次数

类型定义中的感叹号

目前我偶然发现了 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或未定义”,或者这种语法在这种情况下是否有其他特定含义?

typescript angular

6
推荐指数
1
解决办法
3637
查看次数

如何使用 typescript 在 vue3 设置脚本中导入类型?

我想在打字稿中使用<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)

typescript vuejs3 vite

5
推荐指数
1
解决办法
7021
查看次数

使用 keycloak.protect() 和 express.Router()

我想使用 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)

node.js keycloak

3
推荐指数
1
解决办法
7145
查看次数

node_modules/@ngrx/store/src/models.d.ts(58,58) 中的错误:错误 TS2304:找不到名称“未知”

我正在尝试使用 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)

rxjs ngrx angular

3
推荐指数
1
解决办法
4372
查看次数

Nginx:带有 Web 组件的 Angular 应用程序 - 脚本类型 =“模块”错误

我想通过一个简单的 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 …

nginx ecmascript-6 server angular

2
推荐指数
1
解决办法
6308
查看次数

如何删除 wagtail URL 中的“home”

我有一个 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' 来自哪里,我该如何摆脱它?

wagtail

1
推荐指数
1
解决办法
203
查看次数