add an auth callback for web
This commit is contained in:
@@ -331,6 +331,9 @@ func serve(cctx *cli.Context) error {
|
||||
e.GET("/starter-pack-short/:code", server.WebGeneric)
|
||||
e.GET("/start/:handleOrDID/:rkey", server.WebStarterPack)
|
||||
|
||||
// auth callback
|
||||
e.GET("/auth/web/callback", server.WebGeneric)
|
||||
|
||||
// ipcc
|
||||
e.GET("/ipcc", server.WebIpCC)
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"client_name": "Bluesky (Hailey Demo)",
|
||||
"client_uri": "https://bsky.hailey.at",
|
||||
"redirect_uris": [
|
||||
"https://bsky.hailey.at/auth/callback"
|
||||
"https://bsky.hailey.at/auth/web/callback"
|
||||
],
|
||||
"scope": "atproto transition:generic",
|
||||
"token_endpoint_auth_method": "none",
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"client_name": "Bluesky Native App (Hailey Demo)",
|
||||
"client_uri": "https://bsky.hailey.at",
|
||||
"redirect_uris": [
|
||||
"at.hailey.bsky:/auth/callback"
|
||||
"at.hailey.bsky:/auth/native/callback"
|
||||
],
|
||||
"scope": "atproto transition:generic",
|
||||
"token_endpoint_auth_method": "none",
|
||||
|
||||
@@ -135,6 +135,7 @@ import {router} from '#/routes'
|
||||
import {Referrer} from '../modules/expo-bluesky-swiss-army'
|
||||
import {useAccountSwitcher} from './lib/hooks/useAccountSwitcher'
|
||||
import {useNonReactiveCallback} from './lib/hooks/useNonReactiveCallback'
|
||||
import {AuthCallback} from './screens/Login/AuthCallback'
|
||||
import {useLoggedOutViewControls} from './state/shell/logged-out'
|
||||
import {useCloseAllActiveElements} from './state/util'
|
||||
|
||||
@@ -600,6 +601,13 @@ function commonScreens(Stack: typeof Flat, unreadCountLabel?: string) {
|
||||
requireAuth: true,
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="AuthCallback"
|
||||
getComponent={() => AuthCallback}
|
||||
options={{
|
||||
title: title(msg`Authenticating...`),
|
||||
}}
|
||||
/>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -82,6 +82,7 @@ export type CommonNavigatorParams = {
|
||||
StarterPackWizard: undefined
|
||||
StarterPackEdit: {rkey?: string}
|
||||
VideoFeed: VideoFeedSourceContext
|
||||
AuthCallback: undefined
|
||||
}
|
||||
|
||||
export type BottomTabNavigatorParams = CommonNavigatorParams & {
|
||||
|
||||
@@ -90,4 +90,5 @@ export const router = new Router<AllNavigatableRoutes>({
|
||||
StarterPackShort: '/starter-pack-short/:code',
|
||||
StarterPackWizard: '/starter-pack/create',
|
||||
VideoFeed: '/video-feed',
|
||||
AuthCallback: '/auth/web/callback',
|
||||
})
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import {useEffect} from 'react'
|
||||
import {useNavigation} from '@react-navigation/native'
|
||||
|
||||
import {type NavigationProp} from '#/lib/routes/types'
|
||||
import {useSessionApi} from '#/state/session'
|
||||
import {getWebOAuthClient} from '#/state/session/oauth'
|
||||
|
||||
export function AuthCallback() {
|
||||
const {loginOauth} = useSessionApi()
|
||||
const navigation = useNavigation<NavigationProp>()
|
||||
|
||||
// TODO: handle errors, loading state, etc...
|
||||
useEffect(() => {
|
||||
const urlStr = window.location.href
|
||||
const url = new URL(urlStr)
|
||||
const params = new URLSearchParams(url.hash.substring(1))
|
||||
|
||||
;(async () => {
|
||||
const client = getWebOAuthClient()
|
||||
const res = await client.callback(params)
|
||||
await loginOauth(res.session, 'LoginForm') // TODO: right context?
|
||||
navigation.navigate('Home')
|
||||
})()
|
||||
}, [loginOauth, navigation])
|
||||
|
||||
return null
|
||||
}
|
||||
@@ -12,7 +12,7 @@ export function createWebOAuthClient() {
|
||||
client_id: 'https://bsky.hailey.at/oauth-client-metadata.json',
|
||||
client_name: 'Bluesky (Hailey Demo)',
|
||||
client_uri: 'https://bsky.hailey.at',
|
||||
redirect_uris: ['https://bsky.hailey.at/auth/callback'],
|
||||
redirect_uris: ['https://bsky.hailey.at/auth/web/callback'],
|
||||
scope: 'atproto transition:generic',
|
||||
token_endpoint_auth_method: 'none',
|
||||
response_types: ['code'],
|
||||
@@ -30,7 +30,7 @@ export function createNativeOAuthClient() {
|
||||
client_id: 'https://bsky.hailey.at/oauth-client-metadata.native.json',
|
||||
client_name: 'Bluesky Native App (Hailey Demo)',
|
||||
client_uri: 'https://bsky.hailey.at',
|
||||
redirect_uris: ['at.hailey.bsky:/auth/callback'],
|
||||
redirect_uris: ['at.hailey.bsky:/auth/native/callback'],
|
||||
scope: 'atproto transition:generic',
|
||||
token_endpoint_auth_method: 'none',
|
||||
response_types: ['code'],
|
||||
|
||||
Reference in New Issue
Block a user