2

问题

我正在使用这个库对Strava进行 OAuth 。在将用户重定向到 Strava 的身份验证页面之前它工作正常,但是一旦用户批准应用程序就会出现问题。错误地,它说 client_id 无效,但实际上不是因为 1)我仔细检查了 2)如果是这种情况,那么在打开身份验证页面时它应该会出错,但它没有。

我不知道调试错误的最佳方法是什么。我尝试在 Xcode 中设置调试器,但它不起作用,因为我没有通过调试点获得清晰的画面。

我在下面粘贴我的代码:

应用程序.js

import { authorize, refresh, revoke } from 'react-native-app-auth';

config = {
    issuer: 'https://www.strava.com/oauth/mobile/authorize',
    clientId: '***',
    clientSecret: '*********',
    redirectUrl: 'myapp://myapp.com/'
    serviceConfiguration: {
      authorizationEndpoint: 'https://www.strava.com/oauth/mobile/authorize',
      tokenEndpoint: 'https://www.strava.com/oauth/token',
      revocationEndpoint: 'https://www.strava.com/oauth/deauthorize'
    },
    additionalParameters: {
      response_type: 'code',
      approval_prompt: 'force',
      grant_type: 'authorization_code'
    },
    scopes: ['activity:read']
  };

try {
    const authState = await authorize(this.config);
} catch (error) {
    console.error(JSON.stringify(error));
}

Info.plist (iOS)

<dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLName</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleURLSchemes</key>
    <array>
        <string>myapp://myapp.com</string>
    </array>
</dict>

AppDelegate.m

#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"myapp"
                                            initialProperties:nil];

  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  UIViewController *rootViewController = [UIViewController new];
  rootViewController.view = rootView;
  self.window.rootViewController = rootViewController;
  [self.window makeKeyAndVisible];
  return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];
#endif
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *, id> *)options {
 return [self.authorizationFlowManagerDelegate resumeExternalUserAgentFlowWithURL:url];
}

@end

我不知道是什么问题。是与代码有关还是我传递数据错误?

4

0 回答 0