I developing an OSGI Bundle on Apache Felix. The bundle expose different API to manage YouTube event live. The bundle services will be exposed through REST services and will be used by users with a web browser (chrome, safari, mozilla).
I generate the credential google for the account (client_secret and client_id) and saved it in a file, then my code use this credential and work fine.
I used this class (found on youtube docs) for authentication:
public static Credential authorize(List<String> scopes, String credentialDatastore) throws IOException {
// Load client secrets.
Reader clientSecretReader = new InputStreamReader(Auth.class.getResourceAsStream("/client_secrets.json"));
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);
// Checks that the defaults have been replaced (Default = "Enter X here").
if (clientSecrets.getDetails().getClientId().startsWith("Enter")
|| clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
LOGGER.info(
"Enter Client ID and Secret from https://console.developers.google.com/project/_/apiui/credential "
+ "into src/main/resources/client_secrets.json");
System.exit(1);
}
// This creates the credentials datastore at ~/.oauth-credentials/${credentialDatastore}
FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialDataStore(datastore)
.build();
// Build the local server and bind it to port 8080
LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();
// Authorize.
return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("myUsername");
}
On first use on log I found this:
Please open the following address in your browser: https://accounts.google.com/o/oauth2/auth?client_id=my_client_id&redirect_uri=http://localhost:8080/Callback&response_type=code&scope=https://www.googleapis.com/auth/youtube
Until i don't type this url int the browser the authentication process was blocked. After type and clicked, the process work fine.
My question is:
when a user use call this service from browser (api REST will wrap this service) the call blocking in the process of authentication, until the url https://accounts.google.com/o/oauth2/auth?client_id=my_client_id&redirect_uri=http://localhost:8080/Callback&response_type=code&scope=https://www.googleapis.com/auth/youtube is typed and called, how client is notified?
I want a transparent authentication to the client. The authentication process must involve only server, exactly OSGI bundles.
Thanks in advance