코드 자체는 이해하기 더 쉽게 TypeScript로 작성되었으나, 주 목표는 Kotlin에서 작성하고 이후에 호환 예정.
import { MeilingClient } from 'meili-ng'
const client = new MeilingClient() // 기본값은 https://meiling.stella-api.dev
const client = new MeilingClient("https://meiling.debugman.win")// 여기서 클래스 이름 고민중
import { MeilingCredentials, MeilingAuthorizationMethod } from 'meili-ng'
const credential_one = new MeilingCredentials({
authMethod: MeilingAuthorizationMethod.CODE,
clientId: "ab5e527f-2d11-4b93-b9ba-33081bc8eec5",
scopes: ["openid", "email"]
})
return credential_one.generateUrl()
// https://accounts.stella-it.com/auth?client_id=ab5e527f-2d11-4b93-b9ba-33081bc8eec5&response_type=code&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=openid%20email
// 혹은
return credential_one.generateUrl("other_redirect_url")
// code를 획득하였다면 다음과 같이 작성
const credential_two = new MeilingCredentials({
authMethod: MeilingAuthorizationMethod.AUTHORIZATION_CODE,
clientId: "ab5e527f-2d11-4b93-b9ba-33081bc8eec5",
clientSecret: "xxxxxxxxxxxxxxxxxxxxxxxxx"
})
await credential_two.authorize("insert_code_here")
// = { access_token = "xxxxxx", refresh_token = "xxxxxx", expires_in = 36000 }// 여기서 클래스 이름 고민중
import { MeilingCredentials, MeilingAuthorizationMethod } from 'meili-ng'
const challenge = "challenge-text"
const credential_one = new MeilingCredentials({
authMethod: MeilingAuthorizationMethod.CODE,
clientId: "ab5e527f-2d11-4b93-b9ba-33081bc8eec5",
scopes: ["openid", "email"],
challenge: challenge // sdk will automaticlly hash the value and pass into the query string
})
return credential_one.generateUrl()
// https://accounts.stella-it.com/auth?client_id=ab5e527f-2d11-4b93-b9ba-33081bc8eec5&response_type=code&redirect_uri=urn%3Aietf%3Awg%3Aoauth%3A2.0%3Aoob&scope=openid%20email
// 혹은
return credential_one.generateUrl("other_redirect_url")
// code를 획득하였다면 다음과 같이 작성
const credential_two = new MeilingCredentials({
authMethod: MeilingAuthorizationMethod.AUTHORIZATION_CODE,
clientId: "ab5e527f-2d11-4b93-b9ba-33081bc8eec5",
clientSecret: "xxxxxxxxxxxxxxxxxxxxxxxxx"
})
await credential_two.authorize("insert_code_here", challenge)
// = { access_token = "xxxxxx", refresh_token = "xxxxxx", expires_in = 36000 }// 토큰 작성 생략
const oauthData = new MeilingOAuthData(await credential.authorize(....))
oauthData.refresh()await credential.revoke()
// This will destroy every property in credential instance.client.setOAuthData(oauthData)
await client.get("https://connect.roto.win/callback") // = HttpResponse
await client.get("https://connect.roto.win/callback", null, {
header: [
'accept-encoding': 'utf8'
]
}) // = HttpResponse
await client.post("https://connect.roto.win/callback", {
random: objected
}) // = HttpResponse