Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Use wellknown to discover the IS of a HS (element-hq/riot-android#3283)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty authored and BillCarsonFr committed Sep 24, 2019
1 parent f4f4b5b commit 898e079
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Features:
Improvements:
- Display correctly the revoked third-party invites.
- Support optional default STUN server when no ICE provided by HS
- Use wellknown to discover the IS of a HS (vector-im/riot-android#3283)

Bugfix:
-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.matrix.androidsdk.rest.model.WellKnown
import java.io.EOFException
import java.net.MalformedURLException
import java.net.URL
import java.security.InvalidParameterException
import javax.net.ssl.HttpsURLConnection

/**
Expand Down Expand Up @@ -99,7 +100,7 @@ class AutoDiscovery {
if (e is HttpException) {
when (e.httpError.httpCode) {
HttpsURLConnection.HTTP_NOT_FOUND -> callback.onSuccess(DiscoveredClientConfig(Action.IGNORE))
else -> callback.onSuccess(DiscoveredClientConfig(Action.FAIL_PROMPT))
else -> callback.onSuccess(DiscoveredClientConfig(Action.FAIL_PROMPT))
}
} else if (e is MalformedJsonException || e is EOFException) {
callback.onSuccess(DiscoveredClientConfig(Action.FAIL_PROMPT))
Expand Down Expand Up @@ -182,4 +183,20 @@ class AutoDiscovery {
false
}
}

/**
* Try to get an identity server URL from a home server URL, using a .wellknown request
*/
fun getIdentityServer(homeServerUrl: String, callback: ApiCallback<String?>) {
if (homeServerUrl.startsWith("https://")) {
wellKnownRestClient.getWellKnown(homeServerUrl.substring("https://".length),
object : SimpleApiCallback<WellKnown>(callback) {
override fun onSuccess(info: WellKnown) {
callback.onSuccess(info.identityServer?.baseURL)
}
})
} else {
callback.onUnexpectedError(InvalidParameterException("malformed url"))
}
}
}

0 comments on commit 898e079

Please sign in to comment.