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


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I’m relatively new to SSO.  I’ve gotten that callback to work and I can identify the user.  I’m trying to add CSRF protection to the callback, so I know it is coming back from the original request I sent to login.  I thought I’d be able to use get_csrf_token() when displaying the login page, then when I get the callback, I could call get_csrf_token() and I would see the same token in the other controller.  It appears they are different.  As I understand this, I want the tokens to be the same to verify that the call “originated” from my login page.  Furthermore, I have to then render a live_view page, this thread still leaves me confused on the first and 2nd steps.  The tokens are different, and there is a different _csrf_token" =&gt; “token” when the web socket triggers as well as a new _csrf_token" =&gt; “4th_token” when the live view mounts.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="378810" 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/session-csrf-token-versus-liveview-csrf-token/31809/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-378810" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="378810"
                     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 #21"></div>
  </section>
</div>
    <div class="postbit" id="378812" data-post-id="378812">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="garrison" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  garrison
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>You have not specified what you’re implementing but I’ll assume it’s OAuth2.</p>
<p>The purpose of <code>Plug.CSRFProtection</code> is to detect cross-origin requests (using an antiquated method). The auth callback is cross-origin <em>by design</em>, so it’s not going to work there. The spec <a href="https://datatracker.ietf.org/doc/html/rfc6749#section-10.12" rel="noopener nofollow ugc">has a section</a> detailing how to prevent CSRF using the <code>state</code> parameter. CSRF protection is part of the spec.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="378812" 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/session-csrf-token-versus-liveview-csrf-token/31809/23">Post #22</a>
	                </div>
	            </div>
              <div id="likers-container-378812" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="378812"
                     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 #22"></div>
  </section>
</div>
    <div class="postbit" id="378813" data-post-id="378813">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Yes, please excuse me, I’m using OAuth2.  Thank you for sharing the spec.  I understand I can generate the state parameter using what the spec suggested.  Once my other controller gets the callback, what is the proper way to have stored the state so I can check if it matches?</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="378813" 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/session-csrf-token-versus-liveview-csrf-token/31809/24">Post #23</a>
	                </div>
	            </div>
              <div id="likers-container-378813" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="378813"
                     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 #23"></div>
  </section>
</div>
    <div class="postbit" id="378814" data-post-id="378814">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="garrison" src="/assets/icons/user-9f439610.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  garrison
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>You would just stick it in a cookie or in the session (which is probably a cookie). It’s written to be broad because the client is not necessarily a browser.</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"># Login
state = Base.url_encode64(:crypto.strong_rand_bytes(64))
put_session(conn, :oauth_state, state)

# Callback
state = get_session(conn, :oauth_state)
valid? = (state == Map.fetch!(query_params, :state))
</code></pre>
<p>If you are implementing this you should <em>definitely</em> read that spec in full before proceeding.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="378814" 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/session-csrf-token-versus-liveview-csrf-token/31809/25">Post #24</a>
	                </div>
	            </div>
              <div id="likers-container-378814" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="378814"
                     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 #24"></div>
  </section>
</div>
    <div class="postbit" id="379204" data-post-id="379204">
  <section>
    <div class="post-wrap">


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

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi,</p>
<p>Thank you, I ended up implementing it basically exactly how you said, just sticking the state in the session.  I’m going to go through the spec and make sure I’m in compliance.  Thanks again for responding and sharing the spec.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="379204" 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/session-csrf-token-versus-liveview-csrf-token/31809/26">Post #25</a>
	                </div>
	            </div>
              <div id="likers-container-379204" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="379204"
                     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>