Azure-Samples / active-directory-b2c-ios-native-appauth

Demonstrates how you can use a third party library to build an iOS application in Objective-C that authenticates Microsoft identity users to our Azure AD B2C identity service.
http://aka.ms/aadb2c
MIT License
12 stars 8 forks source link

Logout example #6

Open davidvirdeforshh opened 6 years ago

davidvirdeforshh commented 6 years ago

Can you please add a native logout example that starts and ends in the app. This needs to support ios 11 as well as older versions.

Here is a working example in swift 4: `

func logout(viewController: UIViewController) {

    let logoutEndpoint = URL(string: "https://login.microsoftonline.com/te/my_tenant_name.onmicrosoft.com/b2c_1_signup/oauth2/v2.0/logout")!

    let tokenEndpoint = URL(string: "https://login.microsoftonline.com/te/my_tenant_name.onmicrosoft.com/b2c_1_signup/oauth2/v2.0/token")!

    let configuration = OIDServiceConfiguration(authorizationEndpoint: logoutEndpoint, tokenEndpoint: tokenEndpoint)

    let request = OIDAuthorizationRequest(configuration: configuration,
                                                  clientId: self.clientID,
                                                  scopes: scopes,
                                                  redirectURL: URL(string: redirectUri)!,
                                                  responseType: OIDResponseTypeCode,
                                                  additionalParameters: nil)

    let appDelegate = UIApplication.shared.delegate as! AppDelegate

    appDelegate.currentAuthorizationFlow =
        OIDAuthorizationService.present(request, presenting: viewController) {
            (response, error) in
            print("Logged out!")
    }
}

`

sathishTkumar commented 6 years ago

Hi David, When I tried with the sample provided, even after successful sign-in, when I kill and relaunch the app, the login screen is launched again. How you made the user being directly launched on to your home/some other screen and not in Login screen, after your successful login? Can you please help me out in this?

GJDK commented 5 years ago

Thanks for the example @davidvirdeforshh . But when I do logout, am seeing the browser controller pushed-in and popped-out. Is there any way to logout without this browser controller popping-in?