<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="46307" data-post-id="46307">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="wfgilman" data-post="11" data-topic="7749">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wfgilman/48/12467_2.png" class="avatar"> wfgilman:</div>
<blockquote>
<p>I would have to roll my own if I was using Phoenix Token. It’s not stateless, but for long-lived tokens, it doesn’t sound like there is a stateless authentication solution for an API.</p>
</blockquote>
</aside>
<p>Actually there are a variety of helpers that add plugs like Guardian’s for ease of use with phoenix tokens, this is near the top of my search:</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://hex.pm/packages/phoenix_token_plug">
  <header class="source">
      <img src="https://hex.pm/images/hex-full-a8183c4f9adac71516516d107d402b18.svg?vsn=d" class="site-icon" alt="" width="136" height="120">

      <a href="https://hex.pm/packages/phoenix_token_plug" target="_blank" rel="noopener nofollow">Hex</a>
  </header>

  <article class="onebox-body">
    <img width="160" height="160" src="https://hex.pm/images/favicon-160-3770bc59f1f8ba7656b4db5a1eacd8e3.png?vsn=d" class="thumbnail onebox-avatar" alt="">

<h3><a href="https://hex.pm/packages/phoenix_token_plug" target="_blank" rel="noopener nofollow">phoenix_token_plug</a></h3>

  <p>Collection of plugs for Phoenix.Token-based authentication.</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>As well as they are so easy to write manually that there’s almost no point to add a dependency.  ^.^;</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="46307" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-you-do-tokens-and-permissions-rest/7749/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-46307" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="46307"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="46319" data-post-id="46319">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="wfgilman" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wfgilman/120/12467_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  wfgilman
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Just curious, but why discourage using Guardian? Do you think it’s overkill?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="46319" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-you-do-tokens-and-permissions-rest/7749/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-46319" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="46319"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="46320" data-post-id="46320">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group quote-modified" data-username="wfgilman" data-post="13" data-topic="7749" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wfgilman/48/12467_2.png" class="avatar"> wfgilman:</div>
<blockquote>
<p>Just curious, but why discourage using Guardian? Do you just thing it’s overkill?</p>
</blockquote>
</aside>
<p>Other than it is the wrong abstraction?  A couple of other reasons:</p>
<ul>
<li>Significantly larger in payload because of all the packed json stuff required by the JWT spec.</li>
<li>More costly to (de)serialize, which just makes your request take that ever slightly bit longer.</li>
<li><em>Yet Another</em> dependency when it adds about nothing unless JWT is really needed.</li>
<li>To use it properly you either need to push it in the DB yourself anyway or bring in <em>Yet Another</em> dependency like guardian_db.</li>
</ul>
<p>Etc…  ^.^;</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="46320" data-batch-url="/posts/batch_likers">
                        4
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-you-do-tokens-and-permissions-rest/7749/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-46320" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="46320"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="46327" data-post-id="46327">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="wfgilman" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wfgilman/120/12467_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  wfgilman
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Thanks, I appreciate your thoughtful comments as always.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="46327" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-you-do-tokens-and-permissions-rest/7749/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-46327" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="46327"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="46328" data-post-id="46328">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="OvermindDL1" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/OvermindDL1/120/2677_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  OvermindDL1
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="wfgilman" data-post="15" data-topic="7749" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wfgilman/48/12467_2.png" class="avatar"> wfgilman:</div>
<blockquote>
<p>Thanks, I appreciate your thoughtful comments as always.</p>
</blockquote>
</aside>
<p>Thanks, I try.  <img src="https://forum.elixirforum.com/images/emoji/apple/slight_smile.png?v=15" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>
<p>And another note:</p>
<aside class="quote no-group" data-username="wfgilman" data-post="13" data-topic="7749">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/wfgilman/48/12467_2.png" class="avatar"> wfgilman:</div>
<blockquote>
<p>Do you think it’s overkill?</p>
</blockquote>
</aside>
<p>It is not that it is overkill, Phoenix Tokens and JWT tokens can encode the same information, it is just that JWT is designed for arbitrary (as in to/from servers that you do not control) server-to-server communication and has a lot of overhead because of that so the format is ‘universal’.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="46328" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-you-do-tokens-and-permissions-rest/7749/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-46328" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="46328"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="46460" data-post-id="46460">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="voger" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/voger/120/3322_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  voger
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hello, since we are in the topic of tokens, I have a question. I hope it doesn’t skew too much from this thread’s topic.</p>
<p>In “Programming Phoenix” page 186 it says</p>
<blockquote>
<p>For request/response–type applications, session-based authentication makes<br>
sense. For channels, token authentication works better because the connection<br>
is a long-duration connection. With token authentication, we assign a unique<br>
token to each user. Tokens allow for a secure authentication mechanism that<br>
doesn’t rely on any specific transport.</p>
</blockquote>
<blockquote>
<p>Programmers often ask why they can’t access their session cookies in a<br>
channel. The answer is that this would be insecure over WebSockets because<br>
of cross-domain attacks. Also, cookies would couple channel code to the<br>
WebSocket transport, eliminating future transport layers. Fortunately, Phoenix<br>
has a better way: the Phoenix.Token.</p>
</blockquote>
<p>Here is my translation. Please tell me if I am wrong</p>
<blockquote>
<p>For channels, token authentication works better because the connection<br>
is a long-duration connection.</p>
</blockquote>
<p>It would be silly to hit the db every few seconds just to retrieve the session</p>
<blockquote>
<p>Also, cookies would couple channel code to the<br>
WebSocket transport, eliminating future transport layers.</p>
</blockquote>
<p>If you don’t want HTTP that’s fine. Use something else. Just send the token</p>
<blockquote>
<p>Programmers often ask why they can’t access their session cookies in a<br>
channel. The answer is that this would be insecure over WebSockets because<br>
of cross-domain attacks.</p>
</blockquote>
<p>Can someone explain this last point?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="46460" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/how-do-you-do-tokens-and-permissions-rest/7749/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-46460" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="46460"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>