kemalcr/kemal/kemal-oauth
Claude Code and agent skill by kemalcr/kemal
- community
Checking that the SKILL.md file is still in the repository.
Implementing OAuth2 authentication in Kemal, following established project patterns.
Install
npx vskill@latest install kemalcr/kemal/kemal-oauthSKILL.md
The same SKILL.md was published earlier as kemalcr/kemal/kemal-oauth.
Kemal OAuth2 Integration
This skill provides expert guidance on integrating OAuth2 authentication (e.g., GitHub, Google) into Kemal applications, strictly following patterns from `kemal-by-example/oauth-login`.
Core Mandates
- Dependencies: The route examples below use
env.sessionandenv.flash, both provided by `kemal-session` (env.flashsince kemal-session 1.4.0). Add it toshard.ymlandrequire "kemal-session". - Configuration: Use environment variables for client IDs and secrets:
```crystal def client_id : String ENV["GITHUB_CLIENT_ID"]? || "" end
def client_secret : String ENV["GITHUB_CLIENT_SECRET"]? || "" end
def redirect_uri : String ENV["OAUTH_REDIRECT_URI"]? || "http://127.0.0.1:3000/auth/github/callback" end ```
- Authorization URL: Use
URI::Paramsto construct the authorization URL with required scopes and a state parameter:
``crystal def authorize_url(state : String) : String params = URI::Params.build do |form| form.add "client_id", client_id form.add "redirect_uri", redirect_uri form.add "scope", "read:user user:email" form.add "state", state end "https://github.com/login/oauth/authorize?#{params}" end ``
- State Parameter: Generate state with
Random::Secure.random_bytes(16).hexstring, store inenv.session, verify in callback, then delete:
```crystal # In authorization route: state = Random::Secure.random_bytes(16).hexstring env.session.string("oauth_state", state)
# In callback: stored = env.session.string?("oauth_state") env.session.delete_string("oauth_state") halt env.status(:forbidden) unless state == stored ```
- Exchanging Code: Use
HTTP::Clientto exchange the authorization code for an access token. Always setAccept,Content-Type, andUser-Agentheaders:
``crystal response = HTTP::Client.post( "https://github.com/login/oauth/access_token", headers: HTTP::Headers{ "Accept" => "application/json", "Content-Type" => "application/x-www-form-urlencoded", "User-Agent" => "my-app", }, body: URI::Params.encode({ "client_id" => client_id, "client_secret" => client_secret, "code" => code, "redirect_uri" => redirect_uri, }) ) return nil unless response.success? json = JSON.parse(response.body) json["access_token"]?.try(&.as_s?) rescue JSON::ParseException nil ``
Patterns from Source Code
OAuth Service Module (oauth-login/src/services/github_oauth.cr)
OAuth Routes (oauth-login/src/routes/oauth.cr)
env.flash below is kemal-session's one-time flash message helper (see Dependencies above).
Best Practices
- Service Isolation: Encapsulate OAuth logic within dedicated service modules (e.g.,
GithubOauth). - Error Handling: Gracefully handle API errors and JSON parsing failures during the OAuth flow using specific exception types.
- Session Security: Use
env.sessionfor state management throughout the OAuth lifecycle. Always clean up state after verification. - Profile Fetching: Use the access token to fetch user profile information using
HTTP::Clientwith appropriateAuthorization: Bearerheaders. - Configured Check: Check if OAuth is configured before redirecting to avoid errors.
When to Use
- When implementing "Login with GitHub/Google" features.
- When interacting with external APIs that require OAuth2 authentication.
- When managing OAuth flows and callbacks in a Kemal application.
Security
- Security scanPassed, 100 of 100Pattern checks on the skill's files.
- Model reviewNot runA model review is scheduled for the next rescan.
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryChecking.github/skills/kemal-oauth/SKILL.md
Popularity
- Repository stars
- 3,918
- Repository forks
- 205
- 7-day trend score
- 41
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/kemalcr/kemal/kemal-oauth)