Integrate Spring MVC framework with Okta OpenId / Oauth2

Hi Team,

Please help me on the Spring MVC and Okta Oauth2 integration. It will be of real help if some one can point me to github links on the same

Thanks in advance.

Hi, @Nataraj. Please take a look at the following samples: GitHub - okta/samples-java-spring: Spring Boot samples

Hi @louie , Thanks for the link, But I am specifically looking for Spring MVC sample, Also like to know where is the controller for the action : /oauth2/authorization/okta. Also, Would like to know how to get the Okta hosted login form to enter username and password.

Thanks in Advance
Nataraj


I am new to the Okta SSO, trying to get the Access token using below code.Am i using right API and package to do this? Please suggest, Thanks in advance

     private com.microsoft.aad.adal4j.AuthenticationResult.AuthenticationResult getAccessToken(
                AuthorizationCode authorizationCode, String currentUri)
                throws Throwable {
            String authCode = authorizationCode.getValue();
            ClientCredential credential = new ClientCredential(clientId,
                    clientSecret);
            com.microsoft.aad.adal4j.AuthenticationContext context = null;
            com.microsoft.aad.adal4j.AuthenticationResult result = null;
            java.util.concurrent.ExecutorService service = null;
            try {
                service = Executors.newFixedThreadPool(1);
                context = new AuthenticationContext("https://dev-xxxxxxx.okta.com/oauth2/oauth2/authorize", true,
                        service);
                Future<AuthenticationResult> future = context.acquireTokenByAuthorizationCode(authCode, new URI(currentUri), credential, null);
                
                result = future.get();
            } catch (ExecutionException e) {
                throw e.getCause();
            } catch(InterruptedException e){
                LOGGER.error(e);
            } catch(MalformedURLException e){
                LOGGER.error("Malformed URL :"+e);
            }finally {
                service.shutdown();
            }

            if (result == null) {
                throw new ServiceUnavailableException(
                        "authentication result was null");
            }
            return result;
        }

I am following this blog for the same. Any update on this?