我正在尝试使用cordova对iOS进行auth0锁定.它似乎工作,但是当我在插件完成后解除视图时我做错了.它被解雇但我不能再与科尔多瓦视图互动.它变得反应迟钝.
这是插件代码:
@implementation lockPlugin
-(void)init:(CDVInvokedUrlCommand*)command {
A0Lock *lock = [A0Lock sharedLock];
A0LockViewController *controller = [lock newLockViewController];
controller.onAuthenticationBlock = ^(A0UserProfile *profile, A0Token *token) {
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{
@"idToken":token.idToken,
@"refreshToken":token.refreshToken,
@"tokenType":token.tokenType,
@"accessToken":token.accessToken,
@"email":profile.email
}];
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
[self.viewController dismissViewControllerAnimated:YES completion:nil];
};
[lock presentLockController:controller fromController:self.viewController];
}
@end
Run Code Online (Sandbox Code Playgroud) 我在我的WebAPI(ASP.NET Core RC1)中使用JwtBearerAuthentication来验证访问我的API的(Auth0)用户.在Startup.cs中,我使用以下代码配置与Auth0的连接.访问API的每个用户访问用户信息我缺少什么?
app.UseJwtBearerAuthentication(options =>
{
options.AutomaticAuthenticate = true;
options.AutomaticChallenge = true;
options.Audience = clientId;
options.Authority = domain;
options.Events = new JwtBearerEvents
{
OnValidatedToken = context =>
{
var claimsIdentity = context.AuthenticationTicket.Principal.Identity as ClaimsIdentity;
claimsIdentity.AddClaim(new Claim("id_token",
context.Request.Headers["Authorization"][0].Substring(context.AuthenticationTicket.AuthenticationScheme.Length + 1)));
return Task.FromResult(0);
}
};
});
Run Code Online (Sandbox Code Playgroud) 我正在构建一个cordova移动应用程序并尝试使用auth0锁定API.我在使用刷新令牌时遇到问题.我可以在authResult中检索刷新令牌,但无法弄清楚如何实际刷新id_token(我想我自己可以编写REST calsl)
在v9文档中,似乎曾经有过一种方法:https://auth0.com/docs/libraries/lock/v9/using-a-refresh-token
lock.getClient().refreshToken(refresh_token, function (err, delegationResult) {
// Get here the new JWT via delegationResult.id_token
});
Run Code Online (Sandbox Code Playgroud)
但是在锁定v10中,似乎这种方法不再存在:https://auth0.com/docs/libraries/lock/v10/api
任何人都可以建议是否有办法使用锁API刷新令牌?
我正在尝试使用Auth0进行社交登录,但我不断获得未定义引用的例外.
import { Injectable } from '@angular/core';
import { tokenNotExpired } from 'angular2-jwt';
// Avoid name not found warnings
declare var Auth0Lock: any;
@Injectable()
export class AuthService {
// Configure Auth0
lock = new Auth0Lock('I have set the ID correctly here', 'and the domain as well', {});
constructor() {
// Add callback for lock `authenticated` event
this.lock.on("authenticated", (authResult) => {
localStorage.setItem('id_token', authResult.idToken);
});
}
public login() {
// Call the show method to display the widget.
this.lock.show();
};
public …Run Code Online (Sandbox Code Playgroud) 我目前正在开发一个Angular 2 Web应用程序,它将使用Auth0进行用户身份验证.
我在Auth0网站上关注了快速入门,但Cannot read property 'WebAuth' of undefined at new AuthService (auth.service.ts:9)即使声明了AuthService,我也收到了错误.
我错过了什么吗?很感谢任何形式的帮助.
这是我的代码
//app.component.ts
import { Component } from '@angular/core';
import { AuthService } from '../../auth/auth.service';
@Component({
selector: 'app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
constructor(public auth: AuthService) {
auth.handleAuthentication();
}
}
Run Code Online (Sandbox Code Playgroud)
//auth.service.ts
import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import 'rxjs/add/operator/filter';
import auth0 from 'auth0-js';
@Injectable()
export class AuthService {
auth0 = new auth0.WebAuth({
clientID: …Run Code Online (Sandbox Code Playgroud) 我正在使用Auth0作为身份验证服务来设置REST API.一切都在发挥作用,但在一个相当奇怪的事件发生后,我的信心有点动摇了.
我的实现基于此处的示例代码(RS256部分)和此处.唯一的修改是我投了PublicKey一个RSAPublicKey.
问题是我想肯定验证会在签名错误时失败.我更改了签名的最后一个字符(我们将说"x")并且令牌仍然经过验证. 但是 - 将其切换为"x" 以外的任何字符或原始生成的字符都会导致其按预期失败.
我的怀疑是,这是由于某种填充/编码/解码/ Base64问题,而我刚刚选择了一个具有相同的前n个位或其他东西的字符?当然,这意味着如果要做出成功的"猜测",它将需要包括令牌的剩余四十亿字符 - 这是它存在的全部要点.所以我并不担心令牌是可猜测的 - 我只是确保我已经正确地实现了验证的要点.
import com.auth0.jwk.Jwk;
import com.auth0.jwk.JwkException;
import com.auth0.jwk.JwkProvider;
import com.auth0.jwk.UrlJwkProvider;
import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.auth0.jwt.interfaces.DecodedJWT;
import java.security.interfaces.RSAPublicKey;
public class Application {
public static void main(String[] args) {
try {
JwkProvider provider = new UrlJwkProvider("<my-provider>");
Jwk jwk = provider.get("<my-key-id>");
String token = "<some-token-passed-from-client>";
RSAPublicKey publicKey = (RSAPublicKey) jwk.getPublicKey();
Algorithm algorithm = Algorithm.RSA256(publicKey, null);
JWTVerifier verifier …Run Code Online (Sandbox Code Playgroud) 我正在遵循这个auth0的教程来使用JWT来保护我的应用程序.
我最终得到了以下WebSecurity配置:
@EnableWebSecurity
@AllArgsConstructor(onConstructor = @__(@Autowired))
public class WebSecurity extends WebSecurityConfigurerAdapter {
private final UserDetailsService userDetailsService;
private final BCryptPasswordEncoder passwordEncoder;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.formLogin()
.and().cors()
.and().csrf()
.disable()
.authorizeRequests()
.antMatchers(HttpMethod.POST, REGISTER_URL).permitAll()
.antMatchers(HttpMethod.POST, LOGIN_URL).permitAll()
.anyRequest().authenticated()
.and()
.addFilter(new JWTAuthorizationFilter(authenticationManager()))
.addFilter(new JWTAuthenticationFilter(authenticationManager()))
// This disables session creation on Spring Security
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder);
}
@Bean
public CorsConfigurationSource corsConfigurationSource() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", new CorsConfiguration().applyPermitDefaultValues());
return …Run Code Online (Sandbox Code Playgroud) 我们有一个使用Auth0来处理所有授权要求的Angular 5应用程序。它已经开发了大约一年。因此,我们最初从Angular2开始,分别升级到3、4和5。缓慢的加载时间一直是一个问题。
我们在项目中使用npm auth0 sdk。它托管在s3存储桶中。该项目使用angular-cli来构建webpack。
其他人有没有经历过?有已知的解决方案吗?我们使用uglify缩小一切。锁定屏幕迅速显示,但是提交用户名/密码以击中回调/服务器身份验证然后加载仪表板的整个过程需要20-30秒。感觉就像一辈子。
我将附加我们的angular-cli.json文件和package.json文件,以使您了解应用程序中的全部内容。
angular-cli.json
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "ng2angle"
},
"apps": [
{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"app/core/preloader/preloader.scss",
"styles.scss"
],
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"app/core/preloader/preloader.js",
"../node_modules/flot/jquery.flot.js",
"../node_modules/jquery.flot.tooltip/js/jquery.flot.tooltip.js",
"../node_modules/flot/jquery.flot.resize.js",
"../node_modules/flot/jquery.flot.pie.js",
"../node_modules/flot/jquery.flot.time.js",
"../node_modules/flot/jquery.flot.categories.js",
"../node_modules/easy-pie-chart/dist/easypiechart.js",
"../node_modules/chart.js/dist/Chart.bundle.js",
"../node_modules/bootstrap/js/modal.js",
"../node_modules/bootstrap/js/dropdown.js",
"../node_modules/bootstrap/js/tooltip.js",
"../node_modules/summernote/dist/summernote.js",
"../node_modules/moment/min/moment-with-locales.min.js"
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts",
"staging": "environments/environment.staging.ts"
}
}
],
"e2e": { …Run Code Online (Sandbox Code Playgroud) 我已经成功使用了Brock Allen 的oidc-client-js库,以Auth0作为我的身份提供者对我的SPA应用程序进行了身份验证。但是,当我尝试使用该库将用户注销时mgr.signoutRedirect({state: "my test"}),会收到错误消息:no end session endpoint。
查看元数据端点会发现存在一个撤销端点。
我已经像这样配置oidc-client-js库:
var settings = {
authority: 'https://susqsofttest.auth0.com/.well-known/openid-configuration',
client_id: 'my client id',
redirect_uri: 'http://localhost:8080/signin-oidc',
post_logout_redirect_uri: 'http://localhost:8080/logout',
response_type: 'id_token token',
scope: 'openid profile email',
revokeAccessTokenOnSignout: true,
automaticSilentRenew: true,
filterProtocolClaims: true,
loadUserInfo: true
};
var mgr = new UserManager(settings);
Run Code Online (Sandbox Code Playgroud)
有什么我想念的想法吗?
在我们的网站上,管理员应该能够以用户(客户端)的身份查看网站。我计划为此使用Auth0,只是注意到他们的模拟功能已被弃用。
我可以在Redux中强制某些登录标志,以允许管理员以用户身份查看,但是,要从API获取用户的任何数据,我要从登录期间Auth0生成的访问令牌中获取用户ID。因此,API将仅从当前登录的用户访问令牌中获取数据。
有人知道有什么方法可以模拟用户吗?我认为通过解析访问令牌中的用户ID来获取该用户的任何数据,从而对我的API施加了限制,如果我错了,请更正我。
我能想到的唯一方法是,如果管理员“以用户身份查看”,则可以在API调用中传递用户的ID。在控制器中,我可以检查用户ID字段是否存在并使用它代替当前登录的用户,但是我认为传递用户ID并不是一个好主意。也许我可以在每个请求上添加一个中间件,并且如果该用户ID在API调用中存在,我可以检查该用户的角色以确保它是可以验证请求的管理员。
你怎么看?关于此方法还有其他想法/批评吗?
谢谢!!
auth0 ×10
angular ×2
java ×2
jwt ×2
access-token ×1
angular-cli ×1
angular2-jwt ×1
angular5 ×1
api ×1
callback ×1
cordova ×1
ios ×1
login ×1
objective-c ×1
reactjs ×1
rsa ×1