Skip to content

Commit

Permalink
Store state using HttpSession
Browse files Browse the repository at this point in the history
  • Loading branch information
sortraev committed Feb 13, 2025
1 parent 19dabaf commit 7fe2036
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/main/java/no/idporten/example/login/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.nimbusds.openid.connect.sdk.AuthenticationRequest;
import com.nimbusds.openid.connect.sdk.Nonce;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

Expand All @@ -20,11 +21,8 @@ public class LoginController {
private final String callbackURIStr = "http://localhost:7040/callback";
private final String endpointURIStr = "https://login.idporten.dev/authorize";

// used to check state in authorization responses.
private State lastState;

@GetMapping(path = "/login")
public String login() {
public String login(HttpSession session) {

ClientID clientID = new ClientID(clientIDStr);

Expand All @@ -47,7 +45,7 @@ public String login() {
.build();

// store state for verification in callback.
lastState = state;
session.setAttribute("lastState", state);

String requestURIStr = request.toURI().toString();
return "redirect:" + requestURIStr;
Expand Down

0 comments on commit 7fe2036

Please sign in to comment.