-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
232 additions
and
0 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
89 changes: 89 additions & 0 deletions
89
...mmonMain/kotlin/work/socialhub/kbsky/api/entity/meta/WellKnownOAuthAuthorizationServer.kt
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,89 @@ | ||
package work.socialhub.kbsky.api.entity.meta | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
class WellKnownOAuthAuthorizationServer { | ||
|
||
@SerialName("issuer") | ||
lateinit var issuer: String | ||
|
||
@SerialName("scopes_supported") | ||
lateinit var scopesSupported: List<String> | ||
|
||
@SerialName("subject_types_supported") | ||
lateinit var subjectTypesSupported: List<String> | ||
|
||
@SerialName("response_types_supported") | ||
lateinit var responseTypesSupported: List<String> | ||
|
||
@SerialName("response_modes_supported") | ||
lateinit var responseModesSupported: List<String> | ||
|
||
@SerialName("grant_types_supported") | ||
lateinit var grantTypesSupported: List<String> | ||
|
||
@SerialName("code_challenge_methods_supported") | ||
lateinit var codeChallengeMethodsSupported: List<String> | ||
|
||
@SerialName("ui_locales_supported") | ||
lateinit var uiLocalesSupported: List<String> | ||
|
||
@SerialName("display_values_supported") | ||
lateinit var displayValuesSupported: List<String> | ||
|
||
@SerialName("authorization_response_iss_parameter_supported") | ||
var authorizationResponseIssParameterSupported: Boolean = false | ||
|
||
@SerialName("request_object_signing_alg_values_supported") | ||
lateinit var requestObjectSigningAlgValuesSupported: List<String> | ||
|
||
@SerialName("request_object_encryption_alg_values_supported") | ||
lateinit var requestObjectEncryptionAlgValuesSupported: List<String> | ||
|
||
@SerialName("request_object_encryption_enc_values_supported") | ||
lateinit var requestObjectEncryptionEncValuesSupported: List<String> | ||
|
||
@SerialName("request_parameter_supported") | ||
var requestParameterSupported: Boolean = false | ||
|
||
@SerialName("request_uri_parameter_supported") | ||
var requestUriParameterSupported: Boolean = false | ||
|
||
@SerialName("require_request_uri_registration") | ||
var requireRequestUriRegistration: Boolean = false | ||
|
||
@SerialName("jwks_uri") | ||
lateinit var jwksUri: String | ||
|
||
@SerialName("authorization_endpoint") | ||
lateinit var authorizationEndpoint: String | ||
|
||
@SerialName("token_endpoint") | ||
lateinit var tokenEndpoint: String | ||
|
||
@SerialName("token_endpoint_auth_methods_supported") | ||
lateinit var tokenEndpointAuthMethodsSupported: List<String> | ||
|
||
@SerialName("token_endpoint_auth_signing_alg_values_supported") | ||
lateinit var tokenEndpointAuthSigningAlgValuesSupported: List<String> | ||
|
||
@SerialName("revocation_endpoint") | ||
lateinit var revocationEndpoint: String | ||
|
||
@SerialName("introspection_endpoint") | ||
lateinit var introspectionEndpoint: String | ||
|
||
@SerialName("pushed_authorization_request_endpoint") | ||
lateinit var pushedAuthorizationRequestEndpoint: String | ||
|
||
@SerialName("require_pushed_authorization_requests") | ||
var requirePushedAuthorizationRequests: Boolean = false | ||
|
||
@SerialName("dpop_signing_alg_values_supported") | ||
lateinit var dpopSigningAlgValuesSupported: List<String> | ||
|
||
@SerialName("client_id_metadata_document_supported") | ||
var clientIdMetadataDocumentSupported: Boolean = false | ||
} |
23 changes: 23 additions & 0 deletions
23
...in/kotlin/work/socialhub/kbsky/api/entity/meta/WellKnownOAuthProtectedResourceResponse.kt
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,23 @@ | ||
package work.socialhub.kbsky.api.entity.meta | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
class WellKnownOAuthProtectedResourceResponse { | ||
|
||
@SerialName("resource") | ||
lateinit var resource: String | ||
|
||
@SerialName("authorization_servers") | ||
lateinit var authorizationServers: List<String> | ||
|
||
@SerialName("scopes_supported") | ||
lateinit var scopesSupported: List<String> | ||
|
||
@SerialName("bearer_methods_supported") | ||
lateinit var bearerMethodsSupported: List<String> | ||
|
||
@SerialName("resource_documentation") | ||
lateinit var resourceDocumentation: String | ||
} |
23 changes: 23 additions & 0 deletions
23
core/src/commonMain/kotlin/work/socialhub/kbsky/api/meta/MetaResource.kt
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,23 @@ | ||
package work.socialhub.kbsky.api.meta | ||
|
||
import work.socialhub.kbsky.api.entity.meta.WellKnownOAuthAuthorizationServer | ||
import work.socialhub.kbsky.api.entity.meta.WellKnownOAuthProtectedResourceResponse | ||
import work.socialhub.kbsky.api.entity.share.Response | ||
|
||
interface MetaResource { | ||
|
||
/** | ||
* Get OAuth Protected Resource | ||
* https://oyster.us-east.host.bsky.network/.well-known/oauth-protected-resource | ||
*/ | ||
fun wellKnownOAuthProtectedResource() | ||
: Response<WellKnownOAuthProtectedResourceResponse> | ||
|
||
|
||
/** | ||
* Get OAuth authorization server | ||
* https://bsky.social/.well-known/oauth-authorization-server | ||
*/ | ||
fun wellKnownOAuthAuthorizationServer() | ||
: Response<WellKnownOAuthAuthorizationServer> | ||
} |
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
46 changes: 46 additions & 0 deletions
46
core/src/commonMain/kotlin/work/socialhub/kbsky/internal/meta/_MetaResource.kt
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,46 @@ | ||
package work.socialhub.kbsky.internal.meta | ||
|
||
import kotlinx.coroutines.runBlocking | ||
import work.socialhub.kbsky.ATProtocolConfig | ||
import work.socialhub.kbsky.api.entity.meta.WellKnownOAuthAuthorizationServer | ||
import work.socialhub.kbsky.api.entity.meta.WellKnownOAuthProtectedResourceResponse | ||
import work.socialhub.kbsky.api.entity.share.Response | ||
import work.socialhub.kbsky.api.meta.MetaResource | ||
import work.socialhub.kbsky.internal.share._InternalUtility.proceed | ||
import work.socialhub.kbsky.util.MediaType | ||
import work.socialhub.khttpclient.HttpRequest | ||
|
||
class _MetaResource( | ||
private val config: ATProtocolConfig | ||
) : MetaResource { | ||
|
||
override fun wellKnownOAuthProtectedResource() | ||
: Response<WellKnownOAuthProtectedResourceResponse> { | ||
return proceed<WellKnownOAuthProtectedResourceResponse> { | ||
runBlocking { | ||
HttpRequest() | ||
.url("${config.pdsUri}.well-known/oauth-protected-resource") | ||
.accept(MediaType.JSON) | ||
.get() | ||
} | ||
}.also { | ||
if (config.updateAuthUri) { | ||
var authUri = it.data.authorizationServers[0] | ||
if (!authUri.endsWith("/")) authUri += "/" | ||
config.authUri = authUri | ||
} | ||
} | ||
} | ||
|
||
override fun wellKnownOAuthAuthorizationServer() | ||
: Response<WellKnownOAuthAuthorizationServer> { | ||
return proceed { | ||
runBlocking { | ||
HttpRequest() | ||
.url("${config.pdsUri}.well-known/oauth-authorization-server") | ||
.accept(MediaType.JSON) | ||
.get() | ||
} | ||
} | ||
} | ||
} |
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
28 changes: 28 additions & 0 deletions
28
core/src/jvmTest/kotlin/work/socialhub/kbsky/meta/MetaTest.kt
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,28 @@ | ||
package work.socialhub.kbsky.meta | ||
|
||
import work.socialhub.kbsky.AbstractTest | ||
import work.socialhub.kbsky.BlueskyFactory | ||
import work.socialhub.kbsky.domain.Service.BSKY_SOCIAL | ||
import work.socialhub.kbsky.domain.Service.OYSTER_US_EAST | ||
import kotlin.test.Test | ||
|
||
class MetaTest : AbstractTest() { | ||
|
||
@Test | ||
fun testWellKnownOAuthProtectedResource() { | ||
val response = BlueskyFactory | ||
.instance(OYSTER_US_EAST.uri) | ||
.meta() | ||
.wellKnownOAuthProtectedResource() | ||
println(response.data.authorizationServers[0]) | ||
} | ||
|
||
@Test | ||
fun testWell() { | ||
val response = BlueskyFactory | ||
.instance(BSKY_SOCIAL.uri) | ||
.meta() | ||
.wellKnownOAuthAuthorizationServer() | ||
println(response.data.issuer) | ||
} | ||
} |