Skip to main content

Here is my code 


func getToken() {


        let client = BoxSDK.getClient(token: "My developer token")


 


        client.users.getCurrent(fields:n"name", "login"]) { (result: Result<User,


          BoxSDKError>) in


            print(result)


          guard case let .success(user) = result else {


              print("Error getting user information")


              return


          }


            print("Authenticated as \(String(describing: user.name))")


        }


        sleep(5)


    }


 


getting this error :


GET https://api.box.com/2.0/users/me?fields=name,login


▷ Headers: 


    ▷ X-Box-UA, Value: agent=box-swift-sdk/3.1.0; env=iPhone Simulator/13.4.1


    ▷ Authorization, Value: Bearer REDACTED


▷ Body:


2021-09-14 16:51:55.269912+0530 BoxIntegrations17767:939307] /NETWORK AGENT] 


 


◁ Status code: 401: unauthorized


◁ Headers: 


    ◁ Strict-Transport-Security, Value: max-age=31536000


    ◁ box-request-id, Value: 0856d81a3ad577e175ac3e38a9cfd72d1


    ◁ x-envoy-upstream-service-time, Value: 54


    ◁ Connection, Value: keep-alive


    ◁ Cache-Control, Value: no-cache, no-store


    ◁ Transfer-Encoding, Value: Identity


    ◁ Content-Type, Value: application/json


    ◁ Www-Authenticate, Value: Bearer realm="Service"


    ◁ Date, Value: Tue, 14 Sep 2021 11:21:55 GMT


◁ Body: {"type":"error","status":401,"code":"unauthorized","help_url":"http:\/\/developers.box.com\/docs\/#errors","message":"Unauthorized - Cannot authorize with this service","request_id":"wcte3xgugdlacg92"}

Hello Arunesh, 


Could you please provide me with the client ID of your application? 


Best,


Kourtney, Box Developer Advocate


ti4oxizefyvxd56kb5v7mjf21ng6afio


Hello Arunesh, 


Apologies for the delay. I believe your app may not be correctly authorized in the enterprise you're authenticating to. It appears they have a setting enabled to disable unpublished applications by default, which means two steps need to be taken to authorize the app. 


Best,


Kourtney, Box Developer Advocate


Reply