2024-07-19

OAuth 2.0 的 PKCE 筆記

PKCE 詳細規格請參閱 RFC7636

我在撰寫 OAuth 2.0 的登入時,會遇到 code_verifiercode_challenge 一直對不起來的狀況。

舉例來說,我請求 token 的參數為

client_id=aaa&
client_secret=bbb&
code=thisisasimpletoken&
code_verifier=HelloWorld&
grant_type=authorization_code

按照規範,我取得 authorization code 的 request 應該是 

client_id=aaa&
response_type=code&
scope=User.Read.All&
response_mode=form_post&
code_challenge_method=S256&
code_challenge=<將“HelloWorld”以 S256 加密後的字串>

2024-06-07

SVG 文字置中

首先是個普通的 SVG:

Hi! quick fox
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 200 200" width="300">
	<g fill="none" stroke="rgba(22, 22, 22, 0.5)">
		<path d="M 90 90 L 110 110 Z"/>
		<path d="M 110 90 L 90 110 Z"/>
	</g>
	<text font-family="Arial, sans-serif" x="100" y="100" font-size="30">Hi! quick fox</text>
</svg>

為了方便辨識,在 (100, 100) 的位置打了個叉。



上面的 SVG 可以看出來,文字無論是 x 軸還是 y 軸都沒有置中。

2024-05-29

Microsoft Email SMTP 設定

不知為何還蠻難找到 MS 365 的 SMTP 設定,在此紀錄

host outlook-apaccentral.office365.com
port 587
protocol smtp
username 你的 Outlook mail,例如 john.smith@live.com
password Outlook 密碼
from username


另外,我是使用 Java + spring, spring 有兩個參數不確定是在其他程式語言對應的數值,所以在這邊先列一下:

spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.auth=true

2024-05-08

multipart Email 的 Content-Disposition 差異

如果我今天要寄一封 E-Mail,內文要有圖片,那整封信的內容可能如下:

Subject: This is a test mail!
From: test@example.com
Content-Type: multipart/mixed; boundary="qwertyuio"

--qwertyuio
Content-Type: text/html; name="example.html"

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8"/>
		<title>Example</title>
	</head>
	<body>
		<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. </p>
		<img alt="" src="cid:28ce9652-4476-4e3c-8e9a-5d1bbae4cd05" />
	</body>
</html>

--qwertyuio
Content-Type: image/jpeg; name="example.jpg"
Content-Disposition: attachment; filename="example.jpg"
Content-ID: 28ce9652-4476-4e3c-8e9a-5d1bbae4cd05

<image content>

--qwertyuio--

2024-05-03

SASS/SCSS處理 CSS 變數的問題

這是我使用他人套件時遇到的坑。

在使用 SASS / SCSS 時,遇到如下的 code

$red: #DB055E;

:root {
	--red: $red
}

.danger {
	color: var(--red)
}

我預期他應該會生成

:root {
	--red: #DB055E;
}
.danger {
	color: var(--red);
}

但實際上卻是生成

:root {
	--red: $red;
}
.danger {
	color: var(--red);
}

2024-01-29

WebDriver 使用筆記

紀錄一下自己在使用瀏覽器 Web Driver 的筆記。

Web Driver 上網查的話,基本上都會告訴你這東西就是模擬瀏覽器,你可以在那進行各種操作。

但,網路上的範例都是 python code,對於厭惡 python 的人,例如我,就非常不友好。

2024-01-18

Maven 自動 Compile SASS/SCSS (使用 us.hebi.sass plugin)

前一篇文章《Maven 自動 Compile SASS/SCSS (使用 nl.geodienstencentrum.maven plugin)》中提到使用 nl.geodienstencentrum.maven 這個 plugin 可以自動 compile SASS。

但這 plugin 是使用已經淘汰的 Ruby SASS(現在推薦使用 Dart SASS),且經過測試,只能支援到 Java 11(我自己是沒有 Java 12 ~ 16),Java 17(含)以上都會出現 Error。

於是我又另外去找,找到 us.hebi.sass 這個 plugin 。

2024-01-09

Golang 需要不同 Go 版本有不同處理

如果我今天有 go code 需要不同版本有不同處理,要如何寫?

例如說, go 1.18 支援泛型了,但我的 code 要舊版,例如 1.17,也能執行。要如何處理