This repository has been archived by the owner on Jan 24, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added in library compatibility for Android API < 20
Added ability to provide ConnectionBuilder implementation by client
- Loading branch information
1 parent
aa2479b
commit 424cff8
Showing
12 changed files
with
400 additions
and
19 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
59 changes: 59 additions & 0 deletions
59
library/src/main/java/com/okta/appauth/android/DefaultOktaConnectionBuilder.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,59 @@ | ||
/* | ||
* Copyright (c) 2017, Okta, Inc. and/or its affiliates. All rights reserved. | ||
* The Okta software accompanied by this notice is provided pursuant to the Apache License, | ||
* Version 2.0 (the "License.") | ||
* | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* | ||
* See the License for the specific language governing permissions and limitations under the | ||
* License. | ||
*/ | ||
|
||
package com.okta.appauth.android; | ||
|
||
import android.net.Uri; | ||
import android.support.annotation.NonNull; | ||
|
||
import net.openid.appauth.Preconditions; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
import java.net.URL; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* This is ConnectionBuilder which provides to AppAuth library and enable TLS v1.2 for < API 20. | ||
*/ | ||
public class DefaultOktaConnectionBuilder implements OktaConnectionBuilder { | ||
/** | ||
* The singleton instance of the Okta default connection builder. | ||
*/ | ||
public static final DefaultOktaConnectionBuilder INSTANCE = new DefaultOktaConnectionBuilder(); | ||
|
||
private static final int CONNECTION_TIMEOUT_MS = (int) TimeUnit.SECONDS.toMillis(15); | ||
private static final int READ_TIMEOUT_MS = (int) TimeUnit.SECONDS.toMillis(10); | ||
|
||
private static final String HTTPS_SCHEME = "https"; | ||
|
||
private DefaultOktaConnectionBuilder() { | ||
// no need to construct instances of this type | ||
} | ||
|
||
@NonNull | ||
@Override | ||
public HttpURLConnection openConnection(@NonNull Uri uri) throws IOException { | ||
Preconditions.checkNotNull(uri, "url must not be null"); | ||
Preconditions.checkArgument(HTTPS_SCHEME.equals(uri.getScheme()), | ||
"only https connections are permitted"); | ||
HttpURLConnection conn = (HttpURLConnection) new URL(uri.toString()).openConnection(); | ||
TlsProvider.enableIfNeeded(conn); | ||
conn.setConnectTimeout(CONNECTION_TIMEOUT_MS); | ||
conn.setReadTimeout(READ_TIMEOUT_MS); | ||
conn.setInstanceFollowRedirects(false); | ||
return conn; | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
library/src/main/java/com/okta/appauth/android/OktaConnectionBuilder.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,41 @@ | ||
/* | ||
* Copyright (c) 2017, Okta, Inc. and/or its affiliates. All rights reserved. | ||
* The Okta software accompanied by this notice is provided pursuant to the Apache License, | ||
* Version 2.0 (the "License.") | ||
* | ||
* You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* | ||
* See the License for the specific language governing permissions and limitations under the | ||
* License. | ||
*/ | ||
|
||
package com.okta.appauth.android; | ||
|
||
import android.net.Uri; | ||
import android.support.annotation.NonNull; | ||
|
||
import java.io.IOException; | ||
import java.net.HttpURLConnection; | ||
|
||
/** | ||
* Creates {@link java.net.HttpURLConnection} instances for use in direct interactions | ||
* with the authorization service, i.e. those not performed via a browser. | ||
* This interface is similar to Connection Builder in app | ||
* {@link net.openid.appauth.connectivity.ConnectionBuilder}. | ||
* In future net.openid.appauth package will be removed and we don't need to provide any classes | ||
* from this package for client | ||
*/ | ||
public interface OktaConnectionBuilder { | ||
/** | ||
* Creates a connection to the specified URL. | ||
* @param uri - Uri | ||
* @throws IOException if an error occurs while attempting to establish the connection. | ||
* @return HttpURLConnection | ||
*/ | ||
@NonNull | ||
HttpURLConnection openConnection(@NonNull Uri uri) throws IOException; | ||
} |
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
Oops, something went wrong.