-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed last update bug and cleaner authentication to OpenDNS API
- Loading branch information
Showing
4 changed files
with
54 additions
and
12 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
26 changes: 26 additions & 0 deletions
26
app/src/main/java/fr/guillaumevillena/opendnsupdater/utils/BasicAuthInterceptor.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package fr.guillaumevillena.opendnsupdater.utils; | ||
|
||
import java.io.IOException; | ||
|
||
import okhttp3.Credentials; | ||
import okhttp3.Interceptor; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
|
||
public class BasicAuthInterceptor implements Interceptor { | ||
|
||
private String credentials; | ||
|
||
public BasicAuthInterceptor(String user, String password) { | ||
this.credentials = Credentials.basic(user, password); | ||
} | ||
|
||
@Override | ||
public Response intercept(Chain chain) throws IOException { | ||
Request request = chain.request(); | ||
Request authenticatedRequest = request.newBuilder() | ||
.header("Authorization", credentials).build(); | ||
return chain.proceed(authenticatedRequest); | ||
} | ||
|
||
} |