melody-auth部署

melody-auth部署
转载于https://mp.weixin.qq.com/s/8xoYGOR78_paAwDznQa6ng邮箱服务发送服务支持SendGrid、Mailgun、Brevo、Resend、Postmark如果同时配置了多个服务商将按 SendGrid → Mailgun → Brevo → Resend → Postmark 的顺序选择可用服务商以resend发送为例在https://resend.com/ 申请发送服务每天免费100封邮件。Brevo每天免费300封邮件Logs可以查看每次发邮件的请求是否成功API keys可以得到需要配置的Token接收服务接收服务需要在Cloudflare里面配置如下认证服务器设置登录登录wrangler login操作D1数据库创建数据库lixiaobo192 melody-auth % wrangler d1 create melody-auth ⛅️ wrangler4.106.0 ──────────────────── ✅ Successfully created DBmelody-authinregion WNAM Created your new D1 database. To access your new D1 Databaseinyour Worker,addthe following snippet to your configuration file:{d1_databases:[{binding:melody_auth,database_name:melody-auth,database_id:8b4f918c-544a-4e2e-a4c6-38d5bf23bd8b}]}删除数据库#注意需要在wrangler.toml文件里面的[[d1_databases]]配置好正确的database_name和database_idlixiaobolixiaobodeMacBook-Pro server % wrangler d1 delete melody-auth ⛅️ wrangler4.106.0(update available4.108.0)─────────────────────────────────────────────── Resource location: remote About to delete remote database DBmelody-auth(8b4f918c-544a-4e2e-a4c6-38d5bf23bd8b). This action is irreversible and will permanently delete all datainthe database. ✔ Ok to proceed? …yesDeleting... Deletedmelody-authsuccessfully.操作KV空间创建KVlixiaobo192 melody-auth % wrangler kv namespace create melody-auth ⛅️ wrangler4.106.0(update available4.107.0)─────────────────────────────────────────────── **Resource location:** remote Creating namespace with titlemelody-auth✨ Success!To access your new KV Namespaceinyour Worker,addthe following snippet to your configuration file:{kv_namespaces:[{binding:melody_auth,id:d02406cf8b834ae3b86c32b191da1961}]}删除KVlixiaobolixiaobodeMacBook-Pro server % wrangler kv namespace delete --namespace-id d02406cf8b834ae3b86c32b191da1961 ⛅️ wrangler4.106.0(update available4.108.0)─────────────────────────────────────────────── Resource location: remote About to delete remote KV namespace id:d02406cf8b834ae3b86c32b191da1961.This action is irreversible and will permanently delete all datainthe KV namespace. ✔ Ok to proceed? …yesDeleting KV namespace id:d02406cf8b834ae3b86c32b191da1961.Deleted KV namespace id:d02406cf8b834ae3b86c32b191da1961.操作Worker删除workerlixiaobolixiaobodeMacBook-Pro server % wrangler delete--namemelody-auth ⛅️ wrangler4.106.0(update available4.108.0)─────────────────────────────────────────────── ✔ Are you sure you want to delete melody-auth? This action cannot be undone. …yesSuccessfully deleted melody-auth配置#在wrangler.toml中追加配置ENVIRONMENTprod#在wrangler.toml中配置AUTH_SERVER_URLAUTH_SERVER_URLyour_url#配置邮箱按照实际情况配置EMAIL_PROVIDER_NAMExxx# The name of your email provider. Available options are smtp, sendgrid, mailgun, brevo, resend, postmarkRESEND_API_KEYxxx# Put your Resend api key here and leave SENDGRID_API_KEY, MAILGUN_API_KEY, BREVO_API_KEY empty if you want to use Resend handle email functionalitiesRESEND_SENDER_ADDRESSxxx部署cdservernpmrun prod:secret:generatenpmrun prod:migration:applynpmrun prod:deploy自定义域名在worker的域中设置自定义的域名和上面的AUTH_SERVER_URL保持一致你可以访问your_url/.well-known/openid-configuration来验证部署是否成功比如{issuer:https://auth.cloudcodec.cc,authorization_endpoint:https://auth.cloudcodec.cc/oauth2/v1/authorize,token_endpoint:https://auth.cloudcodec.cc/oauth2/v1/token,userinfo_endpoint:https://auth.cloudcodec.cc/oauth2/v1/userinfo,revocation_endpoint:https://auth.cloudcodec.cc/oauth2/v1/revoke,scopes_supported:[openid,profile,offline_access,root,read_user,write_user,read_app,write_app,read_role,write_role,read_scope,write_scope,read_org,write_org],response_types_supported:[code],grant_types_supported:[authorization_code,refresh_token,client_credentials],token_endpoint_auth_methods_supported:[client_secret_basic],claims_supported:[sub,email,first_name,last_name,locale],id_token_signing_alg_values_supported:[RS256],jwks_uri:https://auth.cloudcodec.cc/.well-known/jwks.json,code_challenge_methods_supported:[S256]}管理面板设置更新.env文件的配置信息cdmelody-auth/server wrangler d1 execute melody-auth--commandselect * from app--remote构建和部署npmrun cf:buildnpmrun cf:deploy更新redirectUriscdmelody-auth/server wrangler d1 execute melody-auth--commandupdate app set redirectUrishttps://panel.cloudcodec.cc/en/dashboard,https://panel.cloudcodec.cc/fr/dashboard--remote初次配置登陆有权限问题修改用户权限cdmelody-auth/server wrangler d1 execute melody-auth--commandinsert into user_role (userId, roleId) values (1, 1)--remote重新登陆社交登陆支持Google Facebook GitHub Discord Apple以Google为例获取GOOGLE_AUTH_CLIENT_ID参考https://developers.google.com/identity/oauth2/web/guides/get-google-api-clientid?hlzh-cn在wrangler.toml中配置GOOGLE_AUTH_CLIENT_ID配置好之后如下图所示