How i can get user role in iOS SDK?

We have implemented iOS native SDK. We have one query regarding user role. How we can get user role of member while we fetch profile at time of login.

Hey there!

To clarify your question. Are you indeed using iOS Native SDK? Can you link the repo here as you’ve added auth0-spa-js tag which is totally different SDK. Let me know so I can investigate it further.

Yes i need to get role of particular member in IOS native SDK.

I wasn’t able to find a single method from the SDK (GitHub - auth0/Auth0.swift: Auth0 SDK for Apple platforms) that will allow you to fetch it directly but you can use one of the endpoints of our Management API. Here’s the script for it in Swift:

import Foundation

let headers = ["authorization": "Bearer MGMT_API_ACCESS_TOKEN"]

let request = NSMutableURLRequest(url: NSURL(string: "https://YOUR_DOMAIN/api/v2/users/USER_ID/roles")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()

Documentation reference:

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.