SpringBlade 跨域 無法獲取到token


可參考:
https://blog.csdn.net/She_lock/article/details/86241685
https://blog.csdn.net/weixin_42429220/article/details/107891095
https://www.jianshu.com/p/5cf82f092201?tdsourcetag=s_pctim_aiomsg

黎大神解決的

改一下BladeConfiguration這個類就可以了



后端代碼如下

	/**
	 * 跨域配置
	 * @param registry
	 */
	@Override
	public void addCorsMappings(CorsRegistry registry) {
		registry.addMapping("/**")
			.allowCredentials(false)
			.allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE")
			.allowedOrigins("*");
	}


前端代碼

就隨便在vs里面寫的一個頁面,然后用ajax請求一下就可以了


            // 注意
            // URL地址地址是localhost:10000/blade-auth, 不是localhost:1888/api/blade-auth
            // 注意哦,昨天就采坑了 這里


            // 請求授權
            $.ajax({
                type: "POST",
                url: "http://localhost:10000/blade-auth/token?account=admin&grantType=password&password=admin&tenantId=000000",
                dataType: 'json',
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0'
                },
                success: function (response) {
                    console.log(response);

                    // 請求業務接口
                    var accessToken = response.data.accessToken;
                    $.ajax({
                        type: "GET",
                        url: "http://localhost:10000/blade-pms/brand/list?current=1&size=10",
                        dataType: 'json',
                        headers: {
                            'Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0',
                            'Blade-Auth': 'bearer ' + accessToken,
                        },
                        success: function (response2) {
                            console.log(response2);
                        }
                    });

                }
            });


問題1:header中為什么要傳這個'Authorization': 'Basic c2FiZXI6c2FiZXJfc2VjcmV0',以及這個是怎么來的?

原文:https://www.cnblogs.com/longsanshi/p/12740787.html

c2FiZXI6c2FiZXJfc2VjcmV0這個,用base64編碼的方式,解碼后是這樣的:saber:saber_secret
是不是有點恍然大悟的感覺了,標識了當前登錄的客戶端是哪個,以及對應的客戶端密鑰

數據庫對應的地方



前端生成這個的地方


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM