uber / uber-ios-sdk

Uber iOS SDK (beta)
https://developer.uber.com/docs
MIT License
376 stars 125 forks source link

not getting PRIVILEGED SCOPES #85

Closed anupammishra1989 closed 8 years ago

anupammishra1989 commented 8 years ago

Hi, i am using UberRide iOS SDK V 0.5.2 beta , i am making https://sandbox-api.uber.com/v1/requests/currentcall to get the current Ride details but every time i am getting following errors -

error msg- 
{
  "message": "Missing scope: request",
  "code": "unauthorized"
}
error msg-
ridesAuthenticationErrorType -> rawValue -> invalid_scope
Printing description of error:
Error Domain=com.uber.rides-ios-sdk.ridesAuthenticationError Code=15 "Your app is not authorized for the requested scopes." UserInfo={NSLocalizedDescription=Your app is not authorized for the requested scopes.}

For Implicit Grant/ Login Manager Only getting following scopes :ride_widgets, profile, places, history any help will be appreciated.

itstexter commented 8 years ago

Hey Anupam,

Is the request scope checked on the authorizations tab of your app in the developer dashboard (developer.uber.com)?

~Alex

On Aug 22, 2016 07:33, "anupam mishra" notifications@github.com wrote:

Hi, i am using UberRide iOS SDK V 0.5.2 beta , i am making https://sandbox-api.uber.com/v1/requests/currentcall to get the current Ride details but every time i am getting following errors -

  • If request not included in scope:

error msg- { "message": "Missing scope: request", "code": "unauthorized" }

  • If request is included in scope:

error msg- ridesAuthenticationErrorType -> rawValue -> invalid_scope Printing description of error: Error Domain=com.uber.rides-ios-sdk.ridesAuthenticationError Code=15 "Your app is not authorized for the requested scopes." UserInfo={NSLocalizedDescription=Your app is not authorized for the requested scopes.}

For Implicit Grant/ Login Manager getting following scopes :ride_widgets, profile, places, history

any help

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/uber/rides-ios-sdk/issues/85, or mute the thread https://github.com/notifications/unsubscribe-auth/ACcwTxZhRYL2zqnWnNgrfyQGk1T5OG_wks5qibM2gaJpZM4Jp7s7 .

kjanoudi commented 8 years ago

I'm having the same issue - my app is authorized, I am listed as a developer, and in fact the privileged scopes ARE being granted. However, when it comes back from the SSO login, the SDK only reports 2 scopes being granted (profile, history) rather than all the scopes I requested. Again, using the token that it gives me, I AM able to access the privileged scopes anyway, even though the SDK is reporting only two granted scopes?

kjanoudi commented 8 years ago

I'm not 100% certain, @itstexter , but it seems like perhaps this switch/case is missing a few raw value mappings (which happen to match up to the scopes that are missing when i get back the token from SSO login)

https://github.com/uber/rides-ios-sdk/blob/7e4a08c9acecfb24e93830eb4afe77345f23507a/source/UberRides/Model/RidesScope.swift#L164

jbrophy17 commented 8 years ago

It looks like these are separate issues if I'm not mistaken.

@anupamelemental I think the problem you are having is related to the scopes you have allowed. The /requests/current requires the request scope or the all_trips scope. If you only have request you can only access it for trips initiated via the API for your application (which doesn't include trips initiated via the ride request widget). If you have the all_trips scope, you would be able to see all trips, including those initiated via the widget.

If you are trying to get the requests just for testing, I would suggest using the all_trips scope. Currently getting requests for trips initiated via the widget with only the ride_widgets scope is not supported.

@kjanoudi I think what you are seeing is indeed a bug with the SDK. The access token you get back should have all the correct permissions, but it looks like there is a bug parsing those scopes correctly into the AccessToken. You should still be able to use that token, but the grantedScopes variable will not be accurate. If that is indeed the case, can you open a separate issue? (and maybe a PR since you seem to have tracked down exactly where the problem is :) )

kjanoudi commented 8 years ago

@jbrophy17 Done thank you

anupammishra1989 commented 8 years ago

@itstexter & @jbrophy17 - The request scope is not checked on the authorizations tab of My app, I had applied for Full Access of request scope but uber responded with

App development is complete and ready for production. App follows our design guidelines and terms of service. App screencast or screenshots of the Uber functions integrated into your app and using the requested scope(s) are shared with us for review.

Not sure how get a production ready build without access to them. Sandbox is returning unauthorized access for the following scope: request & all_trips

screen shot 2016-08-23 at 12 49 26 pm

jbrophy17 commented 8 years ago

Getting Full Access is not required while you are still developing your application. When authorizing using the email associated with your app (as well as the developer emails you specify on your app dashboard) you are able to get a token for privileged scopes to allow for testing. So if you include the request or all_trips scopes when you authorize, it will work for your email, before getting the Full Access.

However, you mentioned that you are authorizing via implicit grant. Implicit grant can only be used to request non-privileged scopes. If you want be able to hit requests/current, you will need to implement SSO or Authorization Code Grant flow.

anupammishra1989 commented 8 years ago

I tried to with Native Login SSO, unfortunately i am getting error -

Printing description of error:
Error Domain=com.uber.rides-ios-sdk.ridesAuthenticationError Code=13 "The server was unable to understand your request." 
UserInfo={NSLocalizedDescription=The server was unable to understand your request.}

&

there seems to be a problem connecting to Uber. Please go back to myApp and try again. stackoverflow Question

However Deeplink Request, Ride Request Widget, Implicit Grant is giving me non-privileged scopes. Please help me where i am mistaken.

jbrophy17 commented 8 years ago

What version of the native Uber app are you using? As well as your iOS version?

anupammishra1989 commented 8 years ago

native Uber app v2.149.2 & iOS v9.3.2

jbrophy17 commented 8 years ago

Can you share the code you are using for the SSO? That error indicates that there is something wrong with the request that is being made for authentication, so it could possibly be related to how you are setting up the SDK for SSO

anupammishra1989 commented 8 years ago

I am currently running the example codes provided by Uber SDK (Objective C version).

After setting up the app in Uber and also copied the Client ID to the info.plist, I fill in the redirect URL as myapp://callback on both the dashboard and the app info.plist.

I encounter problem when I clicked on the Native Login only provided by the Objective C example.

When I click at theNative Login, the app will redirect on uber native app & after Allowing Access to information I am getting flag UIAlert with a message of There seems to be a problem connecting to Uber. Please go back to AppName and try again.

img_0028

The code for UBSDKLoginTypeNative SSO is -

#import "UBSDKNativeLoginExampleViewController.h"

#import "UBSDKLocalization.h"

#import <UberRides/UberRides-Swift.h>

@interface UBSDKNativeLoginExampleViewController() <UBSDKLoginButtonDelegate>

@property (nonatomic, readonly, nonnull) UBSDKLoginManager *loginManager;
@property (nonatomic, readonly, nonnull) UBSDKLoginButton *blackLoginButton;
@property (nonatomic, readonly, nonnull) UBSDKLoginButton *whiteLoginButton;

@end

@implementation UBSDKNativeLoginExampleViewController

#pragma mark - UIViewController

- (id)init {
    self = [super init];
    if (self) {
        [self _initialSetup];
    }
    return self;
}

#pragma mark - View Lifecycle

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"SSO";

    [self.view addSubview:self.blackLoginButton];
    [self.view addSubview:self.whiteLoginButton];
    [self _addBlackLoginButtonConstraints];
    [self _addWhiteLoginButtonConstraints];
}

#pragma mark - Private

- (void)_initialSetup {
    _loginManager = [[UBSDKLoginManager alloc] initWithLoginType:UBSDKLoginTypeNative];

    NSArray<UBSDKRidesScope *> *scopes = @[UBSDKRidesScope.Profile, UBSDKRidesScope.Places, UBSDKRidesScope.Request];

    _blackLoginButton = ({
        UBSDKLoginButton *loginButton = [[UBSDKLoginButton alloc] initWithFrame:CGRectZero scopes:scopes loginManager:_loginManager];
        loginButton.presentingViewController = self;
        [loginButton sizeToFit];
        loginButton.delegate = self;
        loginButton;
    });

    _whiteLoginButton = ({
        UBSDKLoginButton *loginButton = [[UBSDKLoginButton alloc] initWithFrame:CGRectZero scopes:scopes loginManager:_loginManager];
        loginButton.colorStyle = RequestButtonColorStyleWhite;
        loginButton.presentingViewController = self;
        [loginButton sizeToFit];
        loginButton.delegate = self;
        loginButton;
    });
}

- (void)_addBlackLoginButtonConstraints {
    self.blackLoginButton.translatesAutoresizingMaskIntoConstraints = NO;

    NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:self.blackLoginButton
                                                                         attribute:NSLayoutAttributeCenterX
                                                                         relatedBy:NSLayoutRelationEqual
                                                                            toItem:self.topView
                                                                         attribute:NSLayoutAttributeCenterX
                                                                        multiplier:1.0
                                                                          constant:0.0];
    NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint constraintWithItem:self.blackLoginButton
                                                                         attribute:NSLayoutAttributeCenterY
                                                                         relatedBy:NSLayoutRelationEqual
                                                                            toItem:self.topView
                                                                         attribute:NSLayoutAttributeCenterY
                                                                        multiplier:1.0
                                                                          constant:0.0];
    NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self.blackLoginButton
                                                                       attribute:NSLayoutAttributeWidth
                                                                       relatedBy:NSLayoutRelationEqual
                                                                          toItem:self.topView
                                                                       attribute:NSLayoutAttributeWidth
                                                                      multiplier:1.0
                                                                        constant:-20];

    [self.view addConstraints:@[centerXConstraint, centerYConstraint, widthConstraint]];
}

- (void)_addWhiteLoginButtonConstraints {
    self.whiteLoginButton.translatesAutoresizingMaskIntoConstraints = NO;

    NSLayoutConstraint *centerXConstraint = [NSLayoutConstraint constraintWithItem:self.whiteLoginButton
                                                                         attribute:NSLayoutAttributeCenterX
                                                                         relatedBy:NSLayoutRelationEqual
                                                                            toItem:self.bottomView
                                                                         attribute:NSLayoutAttributeCenterX
                                                                        multiplier:1.0
                                                                          constant:0.0];
    NSLayoutConstraint *centerYConstraint = [NSLayoutConstraint constraintWithItem:self.whiteLoginButton
                                                                         attribute:NSLayoutAttributeCenterY
                                                                         relatedBy:NSLayoutRelationEqual
                                                                            toItem:self.bottomView
                                                                         attribute:NSLayoutAttributeCenterY
                                                                        multiplier:1.0
                                                                          constant:0.0];
    NSLayoutConstraint *widthConstraint = [NSLayoutConstraint constraintWithItem:self.whiteLoginButton
                                                                       attribute:NSLayoutAttributeWidth
                                                                       relatedBy:NSLayoutRelationEqual
                                                                          toItem:self.bottomView
                                                                       attribute:NSLayoutAttributeWidth
                                                                      multiplier:1.0
                                                                        constant:-20];

    [self.view addConstraints:@[centerXConstraint, centerYConstraint, widthConstraint]];
}

- (void)_showMessage:(NSString *)message {
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:message preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *okayAction = [UIAlertAction actionWithTitle:@"Okay" style:UIAlertActionStyleDefault handler:nil];
    [alert addAction:okayAction];
    [self presentViewController:alert animated:YES completion:nil];
}

#pragma mark - Actions

- (void)_loginButtonAction:(UIButton *)button {
    NSArray<UBSDKRidesScope *> *requestedScopes = @[ UBSDKRidesScope.RideWidgets, UBSDKRidesScope.Profile, UBSDKRidesScope.Places ];

    [self.loginManager loginWithRequestedScopes:requestedScopes presentingViewController:self completion:^(UBSDKAccessToken * _Nullable accessToken, NSError * _Nullable error) {
        if (accessToken) {
            [self _showMessage:UBSDKLOC(@"Saved access token!")];
        } else {
            [self _showMessage:error.localizedDescription];
        }
    }];
}

#pragma mark - UBSDKLoginButtonDelegate

- (void)loginButton:(UBSDKLoginButton *)button didLogoutWithSuccess:(BOOL)success {
    if (success) {
        [self _showMessage:UBSDKLOC(@"Logout")];
    }
}

- (void)loginButton:(UBSDKLoginButton *)button didCompleteLoginWithToken:(UBSDKAccessToken *)accessToken error:(NSError *)error {
    if (accessToken) {
        [self _showMessage:UBSDKLOC(@"Saved access token!")];
    } else {
        [self _showMessage:error.localizedDescription];
    }
}

@end
anupammishra1989 commented 8 years ago

@jbrophy17 Now it works from my side by using Native SSO login. Thanks for your Continued support. For the url https://sandbox-api.uber.com/v1/requests/current i am getting response -

{
"meta": {}
"errors": [1]
0:  {
"status": 404
"code": "no_current_trip"
"title": "User is not currently on a trip."
}-
-
}

Sandbox API should give me some dummy value so that i can verify my results.

jbrophy17 commented 8 years ago

Glad to hear everything is working now! I will take a look to see if I can see anything that indicates the root cause.

The sandbox can be setup to return dummy values, please take a look at the sandbox docs and open a separate issue if you need more help

sujeshraveendran commented 7 years ago

Privileged scopes not accessible. The API documentation states that "During development, your account and any five developer accounts you list on the dashboard will be able to authorize these [privileged] scopes without whitelisting." But here i'm unable to use the "request" scope in sanbox and production with UBER SDK loginManager class. I tried all the three options .native .implicit and .authorizationCode on loginManager (let loginManager = LoginManager(loginType: .native). #1 When i try with .native and .authorizationCode i'm getting "An Unknown Error Occured" message ie error is NIL object . when i try with .implicit i'm getting "Server was unable to understand your request" (error NSError? domain: "com.uber.rides-ios-sdk.ridesAuthenticationError" - code: 13 0x0000600000448700). When i remove .request scope and getting accessToken as expected but when i try to call riderequest( ridesClient.requestRide) with this bearerToken i'm getting error status code 401 (title String? "This endpoint requires at least one of the following scopes: request.delegate.tosaccept, request, request.delegate" some). `` // ****LoginManager login function**** @IBAction func login( sender: AnyObject) { // Define which scopes we're requesting // Need to be authorized on your developer dashboard at developer.uber.com let requestedScopes = [RidesScope.profile, RidesScope.request] // Use your loginManager to login with the requested scopes, viewcontroller to present over, and completion block let loginManager = LoginManager(loginType: .native)

    loginManager.login(requestedScopes: requestedScopes, presentingViewController: self) { (accessToken, error) -> () in
        if accessToken != nil {
            //Success! AccessToken is automatically saved in keychain
            self.showMessage("Got an AccessToken!")
            print(accessToken?.tokenString ?? "")
          //  let accessTokenString = "access_token_string"
           // let token = AccessToken(tokenString: accessTokenString)
           // print(token.tokenString ?? "")
            if TokenManager.save(accessToken: accessToken!){
                // Success
                 self.showMessage("Token Saved!")
            } else {
                  self.showMessage("unable to Saved!")
                // Unable to save
            }

            let token1 =      TokenManager.fetchToken()
             print(token1?.tokenString ?? "")

            self.getData()

        } else {
            // Error
            if let error = error {
                self.showMessage(error.localizedDescription)
            } else {
                self.showMessage("An Unknown Error Occured")
            }
        }
    }
}

// **** ridesClient.requestRide function**** func requestRide() {

    // Create ride parameters
  //  self.requestButton.isEnabled = false
    let pickupLocation = CLLocation(latitude: 10.0080, longitude: 76.3623)
    let dropoffLocation = CLLocation(latitude: 10.0159, longitude: 76.3419)
    //        let pickupLocation = CLLocation(latitude: 37.787654, longitude: -122.402760)
    //        let dropoffLocation = CLLocation(latitude: 37.775200, longitude: -122.417587)

    let builder = RideParametersBuilder()
    builder.pickupLocation = pickupLocation
    builder.pickupNickname = "Infopark campus"
    builder.dropoffLocation = dropoffLocation
    builder.dropoffNickname = "Kakkanad"

   // builder.productID = "a1111c8c-c720-46c3-8534-2fcdd730040d"

    // Use the POST /v1/requests endpoint to make a ride request (in sandbox)
    ridesClient.requestRide(parameters: builder.build(), completion: { ride, response in
        DispatchQueue.main.async(execute: {
            self.checkError(response)
            if let ride = ride {
                self.statusLabel.text = "Processing"

                self.updateRideStatus(ride.requestID, index: 0)
            } else {
                //self.requestButton.isEnabled = true
            }
        })
    })
}

scrn1