揪松網支援 OpenID Connect ,因此你現在可以使用揪松網做為開發網站時的登入機制。
請連至個人帳號下方的 Jothon App Manager 頁面建立新的 Johton App ,並利用 AppID 與 Secret 設定你的網站登入機制。使用 nodejs, express, passportjs 與 openid-connect 的後端源碼範例如下:
/* 設定揪松網的 OpenID 資訊 */ issuer = new openidClient.Issuer({ issuer: "https://hack.g0v.tw", authorization_endpoint: "https://hack.g0v.tw/openid/auth", token_endpoint: "https://hack.g0v.tw/openid/token", userinfo_endpoint: "https://hack.g0v.tw/openid/me", jwks_uri: "https://hack.g0v.tw/openid/certs" }); /* 設定 Jothon App 與網站接口 */ passport.use("g0v", new openidClient.Strategy({ client: new issuer.Client({ client_id: "foo" client_secret: "bar" }), params: { redirect_uri: "http://[your.server/[your-g0v-auth-callback]"], scope: "openid email" } }, function(u, p, done) { /* p.username 即為用戶 email ,請接著做取得 / 建立使用者的動作 */ }); yourExpressApp.get("[your-g0v-auth-path"], passport.authenticate("g0v") yourExpressApp.get("[your-g0v-auth-callback"], passport.authenticate("g0v", { successRedirect: "[your-auth-done-path"], failureRedirect: "[your-auth-fail-path"] });
你可以開啟這個連結來嘗試手動使用你的 Jothon App:
你可以自行設計專為揪松登入系統用的按鈕,以下為使用 Bootstrap 4.0 的按鈕樣式參考設計:
g0v 圖示的 SVG 如下,可以 inline SVG 方式使用:
<?xml version="1.0"?> <svg xmlns="http://www.w3.org/2000/svg" width="24px" height="26.583px" viewbox="0 0 24 26.583" style="vertical-align:middle;"> <polygon fill="#c42026" points="24,0 20.812,0 0,26.583 3.236,26.583"/> <path fill="#010101" d="M19.28,9.338c-1.047-1.058-3.062-2.02-7.487-2.02c -4.267,0-6.441,0.946-7.503,2.02 c-0.968,0.978-1.491,2.196-1.491,4.007s0.523, 3.013,1.491,3.991c1.047,1.058,3.157,2.036,7.503,2.036s6.441-0.962,7.487-2.02 c0.968-0.978,1.491-2.196,1.491-4.007C20.771,11.518,20.248,10.316,19.28,9.338z M11.793,16.789c-2.836,0-4.301-0.587-4.931-1.221 c-0.488-0.492-0.835-1.126-0.835 -2.331s0.299-1.855,0.819-2.378c0.646-0.65,2.111-1.173,4.947-1.173s4.253,0.539, 4.915,1.205 c0.52,0.523,0.835,1.142,0.835,2.347s-0.299,1.855-0.819,2.378C16.062, 16.282,14.628,16.789,11.793,16.789z"/> </svg>
或者使用外部圖檔方式 ( 下載連結 ):
若有任何錯誤或問題,請透過 揪松網 Issue Tracker 回報。