Created
June 14, 2018 09:28
-
-
Save vdelacou/6d5589e2a51be3a3cdeefcaf35f876e9 to your computer and use it in GitHub Desktop.
Create Configuration file in spring boot for Auth0 API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.seelix.api.config; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.Configuration; | |
import com.auth0.client.auth.AuthAPI; | |
import com.auth0.client.mgmt.ManagementAPI; | |
import com.auth0.exception.Auth0Exception; | |
import com.auth0.json.auth.TokenHolder; | |
@Configuration | |
public class Auth0ApiConfiguration { | |
private final ApplicationProperties applicationProperties; | |
public Auth0ApiConfiguration(ApplicationProperties applicationProperties) { | |
this.applicationProperties = applicationProperties; | |
} | |
@Bean | |
public AuthAPI authAPI() { | |
String domain = applicationProperties.getSecurity().getAuthentication().getAuth0().getManagement().getDomain(); | |
String clientId = applicationProperties.getSecurity().getAuthentication().getAuth0().getManagement() | |
.getClientId(); | |
String clientSecret = applicationProperties.getSecurity().getAuthentication().getAuth0().getManagement() | |
.getClientSecret(); | |
return new AuthAPI(domain, clientId, clientSecret); | |
} | |
@Bean | |
public ManagementAPI managementAPI(AuthAPI authAPI) throws Auth0Exception { | |
String domain = applicationProperties.getSecurity().getAuthentication().getAuth0().getManagement().getDomain(); | |
String audience = applicationProperties.getSecurity().getAuthentication().getAuth0().getManagement() | |
.getAudience(); | |
TokenHolder tokenHolder = authAPI.requestToken(audience).execute(); | |
return new ManagementAPI(domain, tokenHolder.getAccessToken()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment