Итак, мне помог один из моих друзей, я скопировал класс код из его кода, но у меня он все еще не полностью работает.
Вот что я получаю от logCat:
Код: Выделить всё
onNewIntent LoginGovActivity
Intent data: br.gov.sp.ged://ged/my-callback?state=xxxxxxxxsXs3b78sfa1Jg&session_state=xxxxxxxx-87c8-4f9f-a4d4-46b0ef05ed8c&code=xxxxxxxx-6abb-42ae-810b-1884550ba58e.a51820f7-87c8-4f9f-a4d4-46b0ef05ed8c.34375c15-d1ed-47d4-8eed-xxxxxxxxxxx
intent: Bundle[{com.android.browser.application_id=org.mozilla.firefox}]
ex: null
resp: null
Это работает для моего друга, но не работает для меня.
Моя проблема в том, что параметры «resp» и «ex» для меня всегда имеют значение null.
Это работает для моего друга, но не работает для меня.
p>
Это код класса:
Код: Выделить всё
class LoginGovActivity : AppCompatActivity() {
val CALLBACK_URL = "xxx" // change value to publish it here
val CLIENT_ID = "xxx" // change value to publish it here
var btnLoginGov: Button? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_gov_login)
btnLoginGov = findViewById(R.id.login_gov) as Button
btnLoginGov!!.setOnClickListener(View.OnClickListener {
Log.i(Constantes.DEV_DEBUG_TAG, "login gov br click v1")
loginGovBrV1()
})
}
private fun loginGovBrV1() {
Log.i(Constantes.DEV_DEBUG_TAG,"teste v0")
AuthorizationServiceConfiguration.fetchFromIssuer(
Uri.parse("https://rhsso.idp-hml.sp.gov.br/auth/realms/idpsp"),
AuthorizationServiceConfiguration.RetrieveConfigurationCallback { serviceConfig, ex ->
if (ex != null) {
Log.e(Constantes.DEV_DEBUG_TAG, "Failed to fetch configuration: ${ex.message}")
return@RetrieveConfigurationCallback
}
val authRequest = AuthorizationRequest.Builder(
serviceConfig!!,
CLIENT_ID,
ResponseTypeValues.CODE,
Uri.parse(CALLBACK_URL)
)
.setAdditionalParameters(Collections.singletonMap(
"prefersEphemeralSession",
"false"
))
.setScope("openid")
.build()
Log.i(Constantes.DEV_DEBUG_TAG,"teste v1")
val appAuthConfig = AppAuthConfiguration.Builder().setBrowserMatcher(AnyBrowserMatcher.INSTANCE).build()
val pendingFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_MUTABLE
} else {
PendingIntent.FLAG_UPDATE_CURRENT
}
Log.i(Constantes.DEV_DEBUG_TAG,"teste v2")
val authService = AuthorizationService(this, appAuthConfig)
Log.i(Constantes.DEV_DEBUG_TAG,"teste v3")
val pendingActivityLoginGov = PendingIntent.getActivity(
this,
0,
Intent(this, LoginGovActivity::class.java),
pendingFlags
)
authService.performAuthorizationRequest(
authRequest,
pendingActivityLoginGov
)
Log.i(Constantes.DEV_DEBUG_TAG,"teste v4")
}) // AuthorizationServiceConfiguration
}
override fun onNewIntent(intent: Intent) {
super.onNewIntent(intent)
Log.i(Constantes.DEV_DEBUG_TAG, "onNewIntent LoginGovActivity")
val dataString = intent.dataString
Log.i(Constantes.DEV_DEBUG_TAG, "Intent data: $dataString")
val resp = AuthorizationResponse.fromIntent(intent)
val ex = AuthorizationException.fromIntent(intent)
MyLog.i("intent: " + intent.data)
MyLog.i("intent: " + intent.extras)
MyLog.i("ex: " + ex)
MyLog.i("resp: " + resp)
if (resp != null) {
startTokenExchange(resp)
}
}
private fun startTokenExchange(resp1: AuthorizationResponse) {
MyLog.i("startTokenExchange call")
Log.i(Constantes.DEV_DEBUG_TAG, "startTokenExchange call")
AuthorizationService(this).performTokenRequest(resp1.createTokenExchangeRequest())
{ resp, ex ->
if(resp != null) {
// do some processing
}
}
}
}
Код: Выделить всё
Код: Выделить всё
Мы ценим любую помощь, чтобы понять, почему мой код «AuthorizationResponse.fromIntent(intent)» всегда имеет значение null
Подробнее здесь: https://stackoverflow.com/questions/792 ... onse-fromi