This commit is contained in:
Hailey
2024-04-04 16:53:12 -07:00
parent fd8e8866a1
commit b4741a8e75
2 changed files with 28 additions and 2 deletions
+19
View File
@@ -0,0 +1,19 @@
import {isWeb} from 'platform/detection'
export const OAUTH_CLIENT_ID = 'https://bsky.app'
export const OAUTH_REDIRECT_URI = 'https://bsky.app/auth/callback'
export const OAUTH_SCOPE = 'openid profile email phone offline_access'
export const OAUTH_GRANT_TYPES = ['authorization_code', 'refresh_token']
export const OAUTH_RESPONSE_TYPES = ['code', 'code id_token']
export const DPOP_BOUND_ACCESS_TOKENS = true
export const APPLICATION_TYPE = isWeb ? 'web' : 'native' // TODO what should we put here for native
export const buildOAuthUrl = (serviceUrl: string, state: string) => {
const url = new URL(serviceUrl)
url.searchParams.set('client_id', OAUTH_CLIENT_ID)
url.searchParams.set('redirect_uri', OAUTH_REDIRECT_URI)
url.searchParams.set('response_type', OAUTH_RESPONSE_TYPES.join(' '))
url.searchParams.set('scope', OAUTH_SCOPE)
url.searchParams.set('state', state)
return url.toString()
}
+9 -2
View File
@@ -1,14 +1,21 @@
import React from 'react'
import * as Browser from 'expo-web-browser'
import {buildOAuthUrl, OAUTH_REDIRECT_URI} from 'lib/oauth'
// TODO remove hack
const serviceUrl = 'http://localhost:2583/oauth/authorize'
// Service URL here is just a placeholder, this isn't how it will actually work
export function useLogin(serviceUrl: string | undefined) {
const openAuthSession = React.useCallback(async () => {
if (!serviceUrl) return
const url = buildOAuthUrl(serviceUrl, '123') // TODO replace '123' with the appropriate state
const authSession = await Browser.openAuthSessionAsync(
serviceUrl, // This isn't actually how this will work
'bsky://login', // Replace this as well with the appropriate link
url, // This isn't actually how this will work
OAUTH_REDIRECT_URI, // Replace this as well with the appropriate link
)
if (authSession.type !== 'success') {