Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import retrofit2.http.Url


object AccountDomainAPI {
private const val DEFAULT_DOMAIN = "https://canvas.instructure.com/"
private const val DEFAULT_DOMAIN = "https://sso.canvaslms.com/"

interface AccountDomainInterface {
@GET
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import retrofit2.http.Query

object ErrorReportAPI {

const val DEFAULT_DOMAIN = "https://canvas.instructure.com"
const val DEFAULT_DOMAIN = "https://sso.canvaslms.com"

enum class Severity(val tag: String) {
COMMENT("just_a_comment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ data class OAuthTokenResponse(
val refreshToken: String? = null,
@SerializedName("real_user")
val realUser: TokenUser? = null,
val user: TokenUser? = null
val user: TokenUser? = null,
@SerializedName("canvas_region")
val canvasRegion: String? = null,
)

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ object ApiPrefs : PrefManager(PREFERENCE_FILE_NAME) {

var clientSecret by StringPref("", "client_secret")

var canvasRegion by NStringPref(null, "canvas_region")

var perPageCount = 100

var theme: CanvasTheme? by GsonPref(CanvasTheme::class.java, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ abstract class BaseLoginFindSchoolActivity : BaseCanvasActivity() {
private fun validateDomain(accountDomain: AccountDomain) {
var url: String? = accountDomain.domain!!.lowercase(Locale.getDefault()).replace(" ", "")

//if the user enters nothing, try to connect to canvas.instructure.com
//if the user enters nothing, try to connect to sso.canvaslms.com
if (url!!.trim { it <= ' ' }.isEmpty()) {
url = "canvas.instructure.com"
url = "sso.canvaslms.com"
}

//remove invalid characters at the end of the domain
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import com.instructure.canvasapi2.utils.AnalyticsEventConstants
import com.instructure.canvasapi2.utils.AnalyticsParamConstants
import com.instructure.canvasapi2.utils.ApiPrefs
import com.instructure.canvasapi2.utils.ApiPrefs.accessToken
import com.instructure.canvasapi2.utils.ApiPrefs.canvasRegion
import com.instructure.canvasapi2.utils.ApiPrefs.clientId
import com.instructure.canvasapi2.utils.ApiPrefs.clientSecret
import com.instructure.canvasapi2.utils.ApiPrefs.domain
Expand Down Expand Up @@ -101,8 +102,14 @@ abstract class BaseLoginSignInActivity : BaseCanvasActivity(), OnAuthenticationS

companion object {
const val ACCOUNT_DOMAIN = "accountDomain"
const val SUCCESS_URL = "/login/oauth2/auth?code="
const val ERROR_URL = "/login/oauth2/auth?error=access_denied"
val SUCCESS_URL_COLLECTION = listOf(
"/canvas/login?code=", //success url
"login/oauth2/auth?code=" //legacy success url (needed for the fallback redirect_uri)
)
val ERROR_URL_COLLECTION = listOf(
"/canvas/login?error=access_denied", //error url
"/login/oauth2/auth?error=access_denied" //legacy error url (needed for the fallback redirect_uri)
)

init {
AppCompatDelegate.setCompatVectorFromResourcesEnabled(true)
Expand Down Expand Up @@ -217,13 +224,14 @@ abstract class BaseLoginSignInActivity : BaseCanvasActivity(), OnAuthenticationS
private fun handleShouldOverrideUrlLoading(view: WebView, url: String): Boolean {
if (overrideUrlLoading(view, url)) return true
return when {
url.contains(SUCCESS_URL) -> {
SUCCESS_URL_COLLECTION.any { url.contains(it) } -> {
val responseUrl = SUCCESS_URL_COLLECTION.first { url.contains(it) }
domain = accountDomain.domain!!
val oAuthRequest = url.substring(url.indexOf(SUCCESS_URL) + SUCCESS_URL.length)
val oAuthRequest = url.substring(url.indexOf(responseUrl) + responseUrl.length)
getToken(clientId, clientSecret, oAuthRequest, mGetTokenCallback)
true
}
url.contains(ERROR_URL) -> {
ERROR_URL_COLLECTION.any { url.contains(it) } -> {
clearCookies()
loadUrl(view, authenticationURL, headers)
true
Expand Down Expand Up @@ -454,7 +462,7 @@ abstract class BaseLoginSignInActivity : BaseCanvasActivity(), OnAuthenticationS
//Skip mobile verify
builder.appendQueryParameter("redirect_uri", "urn:ietf:wg:oauth:2.0:oob")
} else {
builder.appendQueryParameter("redirect_uri", "https://canvas.instructure.com/login/oauth2/auth")
builder.appendQueryParameter("redirect_uri", "https://sso.canvaslms.com/canvas/login")
}

//If an authentication provider is supplied we need to pass that along. This should only be appended if one exists.
Expand Down Expand Up @@ -486,6 +494,7 @@ abstract class BaseLoginSignInActivity : BaseCanvasActivity(), OnAuthenticationS
logEvent(AnalyticsEventConstants.LOGIN_SUCCESS, bundle)
refreshToken = token!!.refreshToken!!
accessToken = token.accessToken!!
canvasRegion = token.canvasRegion
@Suppress("DEPRECATION")
ApiPrefs.token = "" // TODO: Remove when we're 100% using refresh tokens

Expand Down Expand Up @@ -577,4 +586,4 @@ abstract class BaseLoginSignInActivity : BaseCanvasActivity(), OnAuthenticationS
}
}, 750)
} //endregion
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ object MobileVerifyAPI {
.cacheControl(CacheControl.FORCE_NETWORK)
.build()
chain.proceed(request)
}.build()
}
.build()

val mobileVerifyBetaEnabled = RemoteConfigUtils.getString(
RemoteConfigParam.MOBILE_VERIFY_BETA_ENABLED)?.equals("true", ignoreCase = true)
Expand All @@ -56,7 +57,7 @@ object MobileVerifyAPI {
val baseUrl = if (mobileVerifyBetaEnabled && domain?.contains(".beta.") == true) {
"https://canvas.beta.instructure.com/api/v1/"
} else {
"https://canvas.instructure.com/api/v1/"
"https://sso.canvaslms.com/api/v1/"
}

return Retrofit.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ object Const {
const val DISCUSSION_REPLY_SUBMITTED = "discussion_reply_submitted"
const val TITLE = "title"
const val BODY = "body"
const val PROFILE_URL = "canvas.instructure.com"
const val PROFILE_URL = "sso.canvaslms.com"
const val CONVERSATION = "conversations"
const val COURSES = "courses"
const val GROUPS = "groups"
Expand Down
Loading