@Test public void directGrantCode() throws Exception { Account user = savedAccountCitizen("user1"); AccountOnceToken oauthDirectAuthorizeToken = accountService.createOauthDirectAuthorizeToken(user); ClientApp clientApp = service.create(dev, "myapp", "ya ~ good", "http: String code = service.directGrantCode(oauthDirectAuthorizeToken.getToken(), clientApp.getClientId(), "feed public", "http: assertTrue(code.length() > 100); OauthAccessTokenDto token = service.createOauthAccessTokenByGrantCode(code, clientApp.getClientId(), "http: assertNotNull(token.getAccessToken()); assertEquals("feed public", token.getScope()); }
@Override public String directGrantCode(String oauthDirectAuthorize, String clientId, String scope, String redirectUri) throws AccessDeniedException { ClientApp clientApp = verifyRedirectUri(clientId, redirectUri).orElseThrow(() -> new IllegalStateException("invalid clientId and redirectUri")); Set<ClientAppScope> clientAppScopes = ClientAppScope.tryParse(scope); if (clientAppScopes.isEmpty()) { throw new IllegalStateException("invalid scope"); } Account account = accountService.oauthDirectAuthorize(oauthDirectAuthorize) .orElseThrow(() -> new AccessDeniedException("direct authorize failed")); return new GrantCode(account.getAccountId(), clientApp.getClientId(), clientApp.getClientSecret(), redirectUri, clientAppScopes).encode(Instant.now().plus(GRANT_CODE_DURATION), oauthSecret); }
ClientAppServiceImpl implements ClientAppService { @Override public String directGrantCode(String oauthDirectAuthorize, String clientId, String scope, String redirectUri) throws AccessDeniedException { ClientApp clientApp = verifyRedirectUri(clientId, redirectUri).orElseThrow(() -> new IllegalStateException("invalid clientId and redirectUri")); Set<ClientAppScope> clientAppScopes = ClientAppScope.tryParse(scope); if (clientAppScopes.isEmpty()) { throw new IllegalStateException("invalid scope"); } Account account = accountService.oauthDirectAuthorize(oauthDirectAuthorize) .orElseThrow(() -> new AccessDeniedException("direct authorize failed")); return new GrantCode(account.getAccountId(), clientApp.getClientId(), clientApp.getClientSecret(), redirectUri, clientAppScopes).encode(Instant.now().plus(GRANT_CODE_DURATION), oauthSecret); } }
ClientAppServiceImpl implements ClientAppService { @Override public String directGrantCode(String oauthDirectAuthorize, String clientId, String scope, String redirectUri) throws AccessDeniedException { ClientApp clientApp = verifyRedirectUri(clientId, redirectUri).orElseThrow(() -> new IllegalStateException("invalid clientId and redirectUri")); Set<ClientAppScope> clientAppScopes = ClientAppScope.tryParse(scope); if (clientAppScopes.isEmpty()) { throw new IllegalStateException("invalid scope"); } Account account = accountService.oauthDirectAuthorize(oauthDirectAuthorize) .orElseThrow(() -> new AccessDeniedException("direct authorize failed")); return new GrantCode(account.getAccountId(), clientApp.getClientId(), clientApp.getClientSecret(), redirectUri, clientAppScopes).encode(Instant.now().plus(GRANT_CODE_DURATION), oauthSecret); }  }
ClientAppServiceImpl implements ClientAppService { @Override public String directGrantCode(String oauthDirectAuthorize, String clientId, String scope, String redirectUri) throws AccessDeniedException { ClientApp clientApp = verifyRedirectUri(clientId, redirectUri).orElseThrow(() -> new IllegalStateException("invalid clientId and redirectUri")); Set<ClientAppScope> clientAppScopes = ClientAppScope.tryParse(scope); if (clientAppScopes.isEmpty()) { throw new IllegalStateException("invalid scope"); } Account account = accountService.oauthDirectAuthorize(oauthDirectAuthorize) .orElseThrow(() -> new AccessDeniedException("direct authorize failed")); return new GrantCode(account.getAccountId(), clientApp.getClientId(), clientApp.getClientSecret(), redirectUri, clientAppScopes).encode(Instant.now().plus(GRANT_CODE_DURATION), oauthSecret); }  @Override ClientApp create(Authorization creator,
      String name,
      String description,
      String callbackUri); @Override ClientApp loadClientAppWithoutCache(String clientId); @Override List<ClientApp> listClientApps(Authorization creator); @Override void update(Authorization creator,
      String clientId,
      String name,
      String description,
      String callbackUri); @Override Optional<ClientApp> verifyRedirectUri(String clientId, String redirectUri); @Override String directGrantCode(String oauthDirectAuthorize,
      String clientId,
      String scope,
      String redirectUri); @Override OauthAccessTokenDto createOauthAccessTokenByGrantCode(String code,
      String clientId,
      String redirectUri); @Override Optional<ClientAppUserAccessToken> verifyAccessToken(@Nullable String rawAccessToken); @Override List<ClientAppUser> listGrantedAppUsers(Authorization authorization); @Override void resetClientAppSecret(Authorization creator, String clientId); @Override void revokeApp(Authorization user, String clientId); @Override boolean validateApp(String clientId, String clientSecret); @Override String generateDebugAccessToken(Authorization creator, String clientId); @Override List<ClientApp> listGrantedApps(Authorization user); }
ClientAppServiceImpl implements ClientAppService { @Override public String directGrantCode(String oauthDirectAuthorize, String clientId, String scope, String redirectUri) throws AccessDeniedException { ClientApp clientApp = verifyRedirectUri(clientId, redirectUri).orElseThrow(() -> new IllegalStateException("invalid clientId and redirectUri")); Set<ClientAppScope> clientAppScopes = ClientAppScope.tryParse(scope); if (clientAppScopes.isEmpty()) { throw new IllegalStateException("invalid scope"); } Account account = accountService.oauthDirectAuthorize(oauthDirectAuthorize) .orElseThrow(() -> new AccessDeniedException("direct authorize failed")); return new GrantCode(account.getAccountId(), clientApp.getClientId(), clientApp.getClientSecret(), redirectUri, clientAppScopes).encode(Instant.now().plus(GRANT_CODE_DURATION), oauthSecret); }  @Override ClientApp create(Authorization creator,
      String name,
      String description,
      String callbackUri); @Override ClientApp loadClientAppWithoutCache(String clientId); @Override List<ClientApp> listClientApps(Authorization creator); @Override void update(Authorization creator,
      String clientId,
      String name,
      String description,
      String callbackUri); @Override Optional<ClientApp> verifyRedirectUri(String clientId, String redirectUri); @Override String directGrantCode(String oauthDirectAuthorize,
      String clientId,
      String scope,
      String redirectUri); @Override OauthAccessTokenDto createOauthAccessTokenByGrantCode(String code,
      String clientId,
      String redirectUri); @Override Optional<ClientAppUserAccessToken> verifyAccessToken(@Nullable String rawAccessToken); @Override List<ClientAppUser> listGrantedAppUsers(Authorization authorization); @Override void resetClientAppSecret(Authorization creator, String clientId); @Override void revokeApp(Authorization user, String clientId); @Override boolean validateApp(String clientId, String clientSecret); @Override String generateDebugAccessToken(Authorization creator, String clientId); @Override List<ClientApp> listGrantedApps(Authorization user);  }