未经授权的Azure功能

时间:2020-04-29 00:27:45

标签: node.js azure azure-active-directory azure-functions

我正在尝试创建一个简单的NodeJS Azure函数,以将用户注册到数据库中。
计划是让用户使用其Facebook帐户注册,然后填写有关他们的基本信息以发送到Azure功能。

我已经拥有数据库以及MySQL查询和基本功能。但是,我在使用x-zumo-auth标头验证功能时遇到问题。

我让用户使用FBSDKLoginKit(适用于iOS)连接到他们的Facebook,然后使用MicrosoftAzureMobile登录Azure。

#import "AppDelegate.h"
#import "ViewController.h"
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <MicrosoftAzureMobile/MicrosoftAzureMobile.h>

@interface ViewController () <FBSDKLoginButtonDelegate>

@end

@implementation ViewController

#pragma mark - UIView Lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    /// Create the login button
    FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
    [loginButton setDelegate:self];

    /// Add the login button to the subview
    loginButton.center = self.view.center;
    [self.view addSubview:loginButton];

    /// If the user is already logged in with Facebook, login with Azure
    if ([FBSDKAccessToken currentAccessToken].tokenString) [self login];
}

#pragma mark - Login

- (void)login {
    MSClient *client = [MSClient clientWithApplicationURLString:@"https://api.example.com/"];
    NSDictionary *dict = @{ @"access_token": [FBSDKAccessToken currentAccessToken].tokenString };

     [client loginWithProvider:@"facebook" token:dict completion:^(MSUser * _Nullable user, NSError * _Nullable error) {
            NSLog(@"%@ %@", user.mobileServiceAuthenticationToken, error);
     }];
}

#pragma mark Facebook Delegate

- (void)loginButton:(nonnull FBSDKLoginButton *)loginButton didCompleteWithResult:(nullable FBSDKLoginManagerLoginResult *)result error:(nullable NSError *)error {
    [self login];
}

- (void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton {

}

@end

一旦收到来自loginWithProvider的成功回复,然后我就使用mobileServiceAuthenticationToken中的x-zumo-auth与Postman进行手动API调用。但是由于某种原因,它一直给我一个Unauthorized错误响应。

但是,当我使用https://api.example.com/.auth/mex-zumo-auth进行API调用时,它会正常响应。我不确定自己在做什么错。

感谢您的协助。

0 个答案:

没有答案