ClientId and clientSecret are now properly implemented

This commit is contained in:
Brian Ford 2015-12-17 17:30:21 -05:00
Родитель ca4f3fcead
Коммит fc220ba7b1
4 изменённых файлов: 33 добавлений и 9 удалений

Просмотреть файл

@ -2,7 +2,17 @@
Based on publish-to-ftp and extending publish-to and basic-credentials this Jenkins plugin publishes artifacts in a post-build to onedrive folders without the need to run a sync client on your build server.
# Configure
# Registration
1. Register your client application on [Mirosoft Developers](http://go.microsoft.com/fwlink/p/?LinkId=193157)
2. The drive is created at the first login. Login into your account in the web browser, otherwise you will get an authentication error if you try to run the SDK with your credentials.
- The user have to be logged in at least once to use your application.
3. A development authentication token can be obtained on [OneDrive authentication](https://dev.onedrive.com/auth/msa_oauth.htm).
4. More details can be found [here](https://dev.onedrive.com/app-registration.htm)
**Once your app is registered you'll want to note both your Client ID and Client Secret. They will be used when configuring you credentials in the next step.**
# Configure Credentials
The first step to configuring the pubish-over Onedrive plugin is to connect your Onedrive account. To do so, navigate to **Jenkins > Credentials**

Просмотреть файл

@ -49,7 +49,7 @@ public class OneDrive {
private final String accessToken;
private int timeout = -1;
private OneFolder workingFolder;
private static final OneDriveSDK sdk = OneDriveFactory.createOneDriveSDK(Config.CLIENT_ID, Config.CLIENT_SECRET, Config.REDIRECT_URI, OneDriveScope.READWRITE);
private static OneDriveSDK sdk = null;
public OneDrive(String accessToken) {
this.accessToken = accessToken;
@ -66,6 +66,7 @@ public class OneDrive {
public boolean connect() throws IOException, OneDriveException {
System.out.println("*** connect");
try {
sdk = OneDriveFactory.createOneDriveSDK(Config.CLIENT_ID, Config.CLIENT_SECRET, Config.REDIRECT_URI, OneDriveScope.READWRITE);
sdk.authenticateWithRefreshToken(accessToken);
} catch (OneDriveException ex) {
throw new OneDriveException("Error connecting to OneDrive, could not be authenticated." + ex);

Просмотреть файл

@ -23,6 +23,8 @@
*/
package org.jenkinsci.plugins.publishoveronedrive.domain;
import com.cloudbees.plugins.credentials.CredentialsProvider;
import com.cloudbees.plugins.credentials.domains.DomainRequirement;
import de.tuberlin.onedrivesdk.OneDriveException;
import de.tuberlin.onedrivesdk.folder.OneFolder;
import hudson.FilePath;
@ -35,8 +37,11 @@ import org.jenkinsci.plugins.publishoveronedrive.impl.OneDriveTransfer;
import org.jenkinsci.plugins.publishoveronedrive.impl.Messages;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.publishoveronedrive.OneDriveToken;
public class OneDriveClient extends BPDefaultClient<OneDriveTransfer> {
@ -58,6 +63,18 @@ public class OneDriveClient extends BPDefaultClient<OneDriveTransfer> {
this.buildInfo = buildInfo;
}
public boolean setClientIdAndSecret() throws IOException, OneDriveException {
List<OneDriveToken> credentials = CredentialsProvider.lookupCredentials(OneDriveToken.class, Jenkins.getInstance(), null, (DomainRequirement) null);
for (OneDriveToken token : credentials) {
if (!token.getClientId().equals("") && !token.getClientSecret().equals("")) {
Config.CLIENT_ID = token.getClientId();
Config.CLIENT_SECRET = token.getClientSecret();
return true;
}
}
return false;
}
@Override
public boolean changeDirectory(final String directory) {
try {
@ -101,9 +118,10 @@ public class OneDriveClient extends BPDefaultClient<OneDriveTransfer> {
}
}
public boolean connect() throws OneDriveException {
public boolean connect() throws OneDriveException, IOException {
setClientIdAndSecret();
try {
return onedrive.isConnected() || onedrive.connect();
return onedrive.connect();
} catch (IOException ioe) {
throw new BapPublisherException(Messages.exception_exceptionOnDisconnect(ioe.getLocalizedMessage()), ioe);
}

Просмотреть файл

@ -25,10 +25,6 @@
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form" xmlns:st="jelly:stapler" >
<!-- <j:invokeStatic className="org.jenkinsci.plugins.publishoveronedrive.domain.Config" method="getAuthorizeUrl"
var="url"/>-->
<f:entry title="Client ID" field="clientId">
<f:textbox />
</f:entry>
@ -38,7 +34,6 @@
</f:entry>
<f:validateButton title="${%Authorize URL}" progress="${%Testing...}" method="getURL" with="clientId,clientSecret" />
<f:entry title="${%Token}" field="authorizationCode">
<f:textbox/>