我正在使用该库对Strava进行OAuth。在将用户重定向到Strava的身份验证页面之前,它可以正常工作,但是一旦用户批准该应用程序,问题就会出现。 错误的是,它说client_id无效,但实际上不是因为1)我仔细检查了2)如果是这种情况,那么在打开身份验证页面时应该给出一个错误,但不是。
我不知道调试错误的最佳方法是什么。我尝试在Xcode中设置调试器,但由于无法通过调试点获得清晰的画面,因此无法正常工作。
我在下面粘贴我的代码:
App.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
我不知道问题是什么。是与代码有关还是我传递数据错误?