<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Avinash Pokhrel</title>
    <description>The latest articles on Forem by Avinash Pokhrel (@xetri).</description>
    <link>https://forem.com/xetri</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3008223%2F84e1a5ec-172b-45a3-9f70-db319d777d6f.jpeg</url>
      <title>Forem: Avinash Pokhrel</title>
      <link>https://forem.com/xetri</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/xetri"/>
    <language>en</language>
    <item>
      <title>Building a Google OAuth CLI in Rust with PKCE (and surviving the borrow checker)</title>
      <dc:creator>Avinash Pokhrel</dc:creator>
      <pubDate>Sat, 04 Apr 2026 15:11:34 +0000</pubDate>
      <link>https://forem.com/xetri/building-a-google-oauth-cli-in-rust-with-pkce-and-surviving-the-borrow-checker-3cij</link>
      <guid>https://forem.com/xetri/building-a-google-oauth-cli-in-rust-with-pkce-and-surviving-the-borrow-checker-3cij</guid>
      <description>&lt;h1&gt;
  
  
  Building a Google OAuth CLI in Rust with PKCE
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;TL;DR&lt;/strong&gt;: I built a tiny CLI that opens a Google login in your browser, receives the OAuth callback, exchanges the code using PKCE, and prints basic public profile info (email, name, picture). It took me about 5 hours in Rust, mainly because of ownership, &lt;code&gt;String&lt;/code&gt; vs &lt;code&gt;&amp;amp;str&lt;/code&gt;, and lifetime wrangling—but the result is a clean, secure local flow that avoids shipping secrets in source control.&lt;/p&gt;




&lt;p&gt;Repository: &lt;a href="https://github.com/xetri/google-oauth-from-cli.rs" rel="noopener noreferrer"&gt;Source Code&lt;/a&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  Why I did this
&lt;/h2&gt;

&lt;p&gt;I wondered how Github CLI login works under the hood, and I wanted to build a similar flow for Google. So I decided to implement it myself. &lt;/p&gt;

&lt;p&gt;Also: I wanted to do it in Rust.&lt;/p&gt;




&lt;h2&gt;
  
  
  The minimal shape of the flow
&lt;/h2&gt;

&lt;p&gt;High level, the app does these things:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Load client config from environment variables&lt;/li&gt;
&lt;li&gt;Generate a PKCE &lt;code&gt;code_verifier&lt;/code&gt; and &lt;code&gt;code_challenge&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Start a local HTTP server bound to &lt;code&gt;localhost:0&lt;/code&gt; (OS chooses the port)&lt;/li&gt;
&lt;li&gt;Build and print the Google authorization URL&lt;/li&gt;
&lt;li&gt;You open the URL and log in&lt;/li&gt;
&lt;li&gt;Google redirects to &lt;code&gt;http://localhost:&amp;lt;port&amp;gt;/oauth/google/callback?code=...&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The app exchanges the &lt;code&gt;code&lt;/code&gt; for tokens using the original &lt;code&gt;code_verifier&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The app decodes the &lt;code&gt;id_token&lt;/code&gt; payload and prints basic public profile info:

&lt;ul&gt;
&lt;li&gt;email&lt;/li&gt;
&lt;li&gt;name&lt;/li&gt;
&lt;li&gt;picture&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That's it. No browser automation, no pasting codes - just a local browser flow.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why PKCE?
&lt;/h2&gt;

&lt;p&gt;If you build a non-confidential client (CLI, desktop, mobile), you can't assume a client secret will stay secret. PKCE ensures that even if an authorization code is intercepted, the attacker can't redeem it without the original &lt;code&gt;code_verifier&lt;/code&gt;. The server verifies that the &lt;code&gt;code_challenge&lt;/code&gt; sent during login matches the &lt;code&gt;code_verifier&lt;/code&gt; sent during the token exchange.&lt;/p&gt;




&lt;h2&gt;
  
  
  The Rust experience (short)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It took longer than Python/JS would have. Much longer.&lt;/li&gt;
&lt;li&gt;The protocol itself is simple; the trouble in my case was dealing with lifetimes, moving/borrowing strings into collections, and convincing the compiler that nothing will outlive its owner.&lt;/li&gt;
&lt;li&gt;The result is robust and fast, but plan for extra time if you're learning Rust and OAuth at the same time.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're in a hurry and don't care about learning Rust, use Python or JS for a prototype.&lt;/p&gt;




&lt;h2&gt;
  
  
  Important setup note
&lt;/h2&gt;

&lt;p&gt;Before running this, create an OAuth client in Google Cloud Console and &lt;strong&gt;choose "Desktop app"&lt;/strong&gt; as the client type. This makes the client configuration suitable for local callback flows. After that, copy &lt;code&gt;/.env.example&lt;/code&gt; to &lt;code&gt;/.env&lt;/code&gt; and fill only these two values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;GOOGLE_OAUTH_CLIENT_ID&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GOOGLE_OAUTH_CLIENT_SECRET&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Everything else (scope, authorization/token endpoints) can be copied from &lt;code&gt;.env.example&lt;/code&gt; shipped in the repo.&lt;/p&gt;




&lt;h2&gt;
  
  
  Running it
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create the desktop OAuth client in Google Cloud.&lt;/li&gt;
&lt;li&gt;Copy &lt;code&gt;.env.example&lt;/code&gt; to &lt;code&gt;.env&lt;/code&gt; and set &lt;code&gt;GOOGLE_OAUTH_CLIENT_ID&lt;/code&gt; and &lt;code&gt;GOOGLE_OAUTH_CLIENT_SECRET&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cargo run --release&lt;/code&gt; (or build and run the binary).&lt;/li&gt;
&lt;li&gt;The CLI prints an authorization URL—open it in your browser and log in.&lt;/li&gt;
&lt;li&gt;After the Google consent screen, the browser will redirect to the temporary localhost server; the CLI prints your &lt;code&gt;email&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt;, and &lt;code&gt;picture&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: the server binds to &lt;code&gt;localhost:0&lt;/code&gt;, so the OS chooses a free port. This avoids port collisions.&lt;/p&gt;




&lt;h2&gt;
  
  
  Security caveats (this is a learning project)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;I use PKCE, which is appropriate for public clients.&lt;/li&gt;
&lt;li&gt;The ID token payload is decoded and read; I do not (in this learning version) fully validate the JWT signature, issuer, audience, nonce, or expiration. For production use, you must validate these claims and verify the token signature.&lt;/li&gt;
&lt;li&gt;The app reads client secrets from &lt;code&gt;.env&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Closing thoughts
&lt;/h2&gt;

&lt;p&gt;This project was my way to learn OAuth (the protocol) and Rust (the language) together. The final flow is clean: the CLI asks the user to log in and returns the public profile info without ever storing secrets in the repo.&lt;/p&gt;

&lt;p&gt;If you want to try it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Fork or clone the repo&lt;/li&gt;
&lt;li&gt;Create a Desktop OAuth client in Google Cloud&lt;/li&gt;
&lt;li&gt;Set the two env vars and run it&lt;/li&gt;
&lt;/ul&gt;




</description>
      <category>rust</category>
      <category>oauth</category>
      <category>google</category>
      <category>pkce</category>
    </item>
    <item>
      <title>From Pixels to Performance: GUI Clock in C !</title>
      <dc:creator>Avinash Pokhrel</dc:creator>
      <pubDate>Sat, 15 Nov 2025 08:27:06 +0000</pubDate>
      <link>https://forem.com/xetri/from-pixels-to-performance-gui-clock-in-c--3c0k</link>
      <guid>https://forem.com/xetri/from-pixels-to-performance-gui-clock-in-c--3c0k</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fenda0rppjuqwugvhmd9a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fenda0rppjuqwugvhmd9a.png" alt=" " width="645" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Excited to share a side project I completed recently: a classic desktop clock GUI implemented entirely in C using two powerful graphics frameworks. This project was a great exercise in low-level, high-performance programming:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;SDL2 (Simple DirectMedia Layer)&lt;/strong&gt;: The C implementation focused on low-level control and graphics pipelines.&lt;br&gt;&lt;br&gt;
&lt;a href="https://github.com/xetri/gclock" rel="noopener noreferrer"&gt;Code&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Raylib&lt;/strong&gt;: This C version prioritized simplicity and rapid development, leveraging its clean, immediate-mode drawing API for a highly performant and lightweight result.&lt;br&gt;&lt;br&gt;
&lt;a href="https://github.com/xetri/gclock/tree/master" rel="noopener noreferrer"&gt;Code&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Key takeaways from this project:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Explored the trade-offs between low-level control (SDL2) and developer productivity (Raylib), all within the constraints of C.
&lt;/li&gt;
&lt;li&gt;Gained experience in cross-platform compilation and dependency management, as reflected in the CI/CD pipeline developed for this project.
&lt;/li&gt;
&lt;li&gt;Confirmed C's unmatched strength in creating lightweight, highly performant desktop applications.&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>sdl2</category>
      <category>raylib</category>
      <category>c</category>
      <category>sideprojects</category>
    </item>
    <item>
      <title>What is Programming ?</title>
      <dc:creator>Avinash Pokhrel</dc:creator>
      <pubDate>Sat, 06 Sep 2025 22:45:08 +0000</pubDate>
      <link>https://forem.com/xetri/what-is-programming--218o</link>
      <guid>https://forem.com/xetri/what-is-programming--218o</guid>
      <description>&lt;h1&gt;
  
  
  Programming: The Art and Science of Telling Computers What to Do
&lt;/h1&gt;

&lt;p&gt;Programming, often called the “language of computers,” is the process of writing instructions that a computer can understand and execute. At its core, it’s about solving problems—taking a real-world challenge, breaking it down into smaller steps, and designing a logical sequence to achieve the desired outcome.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Why Programming Matters
&lt;/h2&gt;

&lt;p&gt;We live in a digital world where almost every device, from smartphones to washing machines, runs on software. Behind that software lies programming. It enables innovation in medicine, finance, entertainment, communication, and even space exploration. Simply put, programming powers modern civilization.  &lt;/p&gt;

&lt;h2&gt;
  
  
  How Programming Works
&lt;/h2&gt;

&lt;p&gt;A computer does not understand human language—it understands only binary (0s and 1s). Programming languages bridge this gap. They allow developers to express ideas in a more human-readable form, which compilers or interpreters then translate into machine code.  &lt;/p&gt;

&lt;p&gt;Some popular programming languages include:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Python&lt;/strong&gt; – Known for simplicity and versatility; widely used in AI and data science.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JavaScript&lt;/strong&gt; – The backbone of web development, making websites interactive.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;C/C++&lt;/strong&gt; – Powerful languages used in operating systems, gaming, and embedded systems.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Go &amp;amp; Rust&lt;/strong&gt; – Modern languages that emphasize performance and safety.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Skills Programming Teaches
&lt;/h2&gt;

&lt;p&gt;Beyond technical ability, programming develops:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Problem-solving&lt;/strong&gt;: Breaking complex tasks into smaller, manageable steps.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Logical thinking&lt;/strong&gt;: Learning to reason systematically.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Creativity&lt;/strong&gt;: Building solutions from scratch.
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Persistence&lt;/strong&gt;: Debugging teaches patience and resilience.
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Future of Programming
&lt;/h2&gt;

&lt;p&gt;As artificial intelligence and automation evolve, some believe programming will become more abstract—focusing less on writing code line by line and more on defining problems and constraints. Yet, the fundamental skill of computational thinking will remain crucial.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Programming is more than just typing code. It’s a creative, logical, and deeply impactful activity that shapes the way we live and work. Whether you dream of building apps, analyzing data, or creating the next big startup, learning programming is an investment that opens endless doors.&lt;/p&gt;

</description>
      <category>deblog</category>
    </item>
  </channel>
</rss>
