Using OAuth2.0 Swift authentication

Hello All,

I am developing an iOS application for crm. I am try to authentication using Oauth2.0. There are in bellow code.

let oauthswift = OAuth2Swift(

            consumerKey: client_id,

            consumerSecret: clientSecret,

            authorizeUrl: authURL,

            accessTokenUrl: accessURL,

            responseType : responseType )

        

        self.oauthswift = oauthswift

        oauthswift.accessTokenBasicAuthentification = true

        oauthswift.authorize(withCallbackURL: callBackURL, scope: scope, state:state, success: { (credentials, response, parameters) in

            // print(response as Any)  

        }, failure: { (error) in

            print(error)

        })

Question :

  1. There are right way to authentication in iOS ?
  2. How can i authenticate using this code ?
  3. After login or  authentication i want to back my application, In suger CRM from where i can set redirect URL ? 
  • Disclaimer: I've never used swift, or even Objective C, for that matter.

    It looks like you're trying to use basic Authentication.  This, I don't believe will work.

    Just make a POST call against the instance's /rest/v11/oauth2/token endpoint.

    You'll need in your JSON the following:

    {

    "grant_type":"password",

    "client_id":"sugar",

    "client_secret":"",

    "username": "<username>",

    "password":"<password>",

    "platform":"<base, or whatever platform you're using>"

    }

    Your method needs to be "POST", and have a property of "Content-Type":"application/json".

    This will return some json, which will include a few things, including an oauth token, which you can use to make other calls.  This token works like a normal session, (will time out and be lost if you log in again on the same platform").

    Once you have a token, you can just include it in your header.  ("Oauth-token":"<retrieved token>")