add oauth client
This commit is contained in:
+6
-3
@@ -3,10 +3,13 @@ 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 OAUTH_GRANT_TYPES = [
|
||||
'authorization_code',
|
||||
'refresh_token',
|
||||
] as const
|
||||
export const OAUTH_RESPONSE_TYPES = ['code', 'code id_token'] as const
|
||||
export const DPOP_BOUND_ACCESS_TOKENS = true
|
||||
export const APPLICATION_TYPE = isWeb ? 'web' : 'native' // TODO what should we put here for native
|
||||
export const OAUTH_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)
|
||||
|
||||
@@ -1,7 +1,17 @@
|
||||
import React from 'react'
|
||||
import * as Browser from 'expo-web-browser'
|
||||
import {OAuthClientFactory} from '@atproto/oauth-client'
|
||||
|
||||
import {buildOAuthUrl, OAUTH_REDIRECT_URI} from 'lib/oauth'
|
||||
import {
|
||||
buildOAuthUrl,
|
||||
DPOP_BOUND_ACCESS_TOKENS,
|
||||
OAUTH_APPLICATION_TYPE,
|
||||
OAUTH_CLIENT_ID,
|
||||
OAUTH_GRANT_TYPES,
|
||||
OAUTH_REDIRECT_URI,
|
||||
OAUTH_RESPONSE_TYPES,
|
||||
OAUTH_SCOPE,
|
||||
} from 'lib/oauth'
|
||||
|
||||
// TODO remove hack
|
||||
const serviceUrl = 'http://localhost:2583/oauth/authorize'
|
||||
@@ -9,6 +19,18 @@ 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 () => {
|
||||
const oauthFactory = new OAuthClientFactory({
|
||||
clientMetadata: {
|
||||
client_id: OAUTH_CLIENT_ID,
|
||||
redirect_uris: [OAUTH_REDIRECT_URI],
|
||||
grant_types: OAUTH_GRANT_TYPES,
|
||||
response_types: OAUTH_RESPONSE_TYPES,
|
||||
scope: OAUTH_SCOPE,
|
||||
dpop_bound_access_tokens: DPOP_BOUND_ACCESS_TOKENS,
|
||||
application_type: OAUTH_APPLICATION_TYPE,
|
||||
},
|
||||
})
|
||||
|
||||
if (!serviceUrl) return
|
||||
|
||||
const url = buildOAuthUrl(serviceUrl, '123') // TODO replace '123' with the appropriate state
|
||||
|
||||
Reference in New Issue
Block a user