change
This commit is contained in:
@@ -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()
|
||||||
|
}
|
||||||
@@ -1,14 +1,21 @@
|
|||||||
import React from 'react'
|
import React from 'react'
|
||||||
import * as Browser from 'expo-web-browser'
|
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
|
// Service URL here is just a placeholder, this isn't how it will actually work
|
||||||
export function useLogin(serviceUrl: string | undefined) {
|
export function useLogin(serviceUrl: string | undefined) {
|
||||||
const openAuthSession = React.useCallback(async () => {
|
const openAuthSession = React.useCallback(async () => {
|
||||||
if (!serviceUrl) return
|
if (!serviceUrl) return
|
||||||
|
|
||||||
|
const url = buildOAuthUrl(serviceUrl, '123') // TODO replace '123' with the appropriate state
|
||||||
|
|
||||||
const authSession = await Browser.openAuthSessionAsync(
|
const authSession = await Browser.openAuthSessionAsync(
|
||||||
serviceUrl, // This isn't actually how this will work
|
url, // This isn't actually how this will work
|
||||||
'bsky://login', // Replace this as well with the appropriate link
|
OAUTH_REDIRECT_URI, // Replace this as well with the appropriate link
|
||||||
)
|
)
|
||||||
|
|
||||||
if (authSession.type !== 'success') {
|
if (authSession.type !== 'success') {
|
||||||
|
|||||||
Reference in New Issue
Block a user