An poc to make a login using Auth0 in Swift

Overview

Swift-Auth0-poc

This app is an poc to make a login using Auth0. If you want to try it yourself here is a small tutorial on how to do it.

1. Configure Auth0

Get your application keys. You can get these keys when creating a new application on Auth0.com. With this link below you can login and go to applications to create a new one.

2. Configure callback URL and logout URL

You can change these URLs in the application settings. The product_bundle_identifier is located in the settings on your application in Xcode.

Product bundle identifier:

com.company.myapp://company.auth0.com/ios/com.company.myapp/callback

Callback and logout URL:

{PRODUCT_BUNDLE_IDENTIFIER}://{YOUR_ACCOUNT}.us.auth0.com/ios/{PRODUCT_BUNDLE_IDENTIFIER}/callback

3. Start authentication

To be able to use Auth0 we need some dependencies. To get these you can add a package to the Swift Package manager. This is the URL for it:

https://github.com/auth0/Auth0.swift.git

4. Implement Login and logout

Add the code below to the file where you want to present the login page:

import Auth0

Then add the following code to add the login and logout button:

struct Homeview: View {
    
    @State private var myToken = ""
    @State private var status = false
    
    var body: some View {
        VStack {
            
            Text("Status: " + (status ? "Logged in" : "Not logged in"))
                .padding()
            
            Button  {
                Auth0
                    .webAuth()
                    .scope("openid profile")
                    .audience("https://dev-nbbojs57.us.auth0.com/userinfo")
                    .start { result in
                        switch result {
                        case .failure(let error):
                            // Handle the error
                            print("Auth- Error: \(error)")
                        case .success(let credentials):
                            // Do something with credentials e.g.: save them.
                            // Auth0 will automatically dismiss the login page
                            print("Auth0 Credentials: \(credentials)")
                            
                            if let token =  credentials.accessToken {
                                myToken = token
                            }
                            status = true
                        }
                }
            } label: {
                Text("Login with Auth0")
                    .padding()
            }
            
            Button {
                Auth0
                    .webAuth()
                    .clearSession(federated: false) { result in
                        if result {
                            // Session cleared
                            print("Logged out")
                        }
                        status = false
                    }
            } label: {
                Text("Logout")
                    .padding()
            }
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        Homeview()
.previewInterfaceOrientation(.portrait)
    }
}
You might also like...
A swift implementation of OAuth2

#AlamofireOauth2 A Swift implementation of OAuth2 for iOS using Alamofire. #Intro This library is heavilly inspired by the SwiftOAuth2 repository from

Declarative Swift framework for Attributed Role-based Access Control management
Declarative Swift framework for Attributed Role-based Access Control management

Koosa Declarative Swift framework for Attributed Role-based Access Control management Check out this blog post for full explanation and more details:

FCLAuthSwift is a Swift library for the Flow Client Library (FCL) that enables Flow wallet authentication on iOS devices.
FCLAuthSwift is a Swift library for the Flow Client Library (FCL) that enables Flow wallet authentication on iOS devices.

FCLAuthSwift is a Swift library for the Flow Client Library (FCL) that enables Flow wallet authentication on iOS devices. Demo The demo a

SFA: Swift Firebase Auth Project✨
SFA: Swift Firebase Auth Project✨

SFAssets SFA: Swift Firebase Auth Project✨ 파이어베이스로 로그인/회원가입 뿌수기 Login View (로그인 뷰) 담당 기능 배정 Facebook Login 후릐 Google Login 태끼 Apple Login 이준초이 Github

Swift async/await OAuth 2.0 HTTP request library.

SwAuth SwAuth is an OAuth 2.0 HTTP request library written in Swift iOS 15.0+, macOS 12.0+, watchOS 8.0+, and tvOS 15.0+. Features Requirements Instal

Swift based OAuth library for iOS and macOS
Swift based OAuth library for iOS and macOS

OAuthSwift Swift based OAuth library for iOS and macOS. Support OAuth1.0, OAuth2.0 Twitter, Flickr, Github, Instagram, Foursquare, Fitbit, Withings, L

This app is a sample app that recognizes specific voice commands such as
This app is a sample app that recognizes specific voice commands such as "make it red", "make it blue", "make it green", and "make it black" and change the background color of the view in the frame.

VoiceOperationSample This app is a sample app that recognizes specific voice commands such as "make it red", "make it blue", "make it green", and "mak

Login-screen-UI - A simple iOS login screen written in Swift 5

This project has been updated to Swift 5 and Xcode 11.2 About This is a simple i

This is an POC for showing current Air Quality of different Cities in graphical format using webSocket
This is an POC for showing current Air Quality of different Cities in graphical format using webSocket

Air-Quality-Monitoring This is an POC for showing current Air Quality of different Cities in graphical format using webSocket. It Used danielgindi/Cha

PoC of function hooking in Swift

SWRoute is a tiny Swift wrapper over rd_route(). It allows you to route (hook) quite any function/method with another function/method or even a closur

A tester tool for the bug PoC released by Synacktiv for 15.0 - 15.4 beta 3

SploitTest A tester tool for the bug PoC released by Synacktiv for 15.0 - 15.4 beta 3 iOS 15.4 patched a kernel vulnerability introduced in iOS 15.0 b

POC for a bug with react-native-webview crashing on IOS 16.1

POC Shared Worker issues with IOS 16.1 webview Apple Developers post with workaround Webkit confirmed issue Start a simple http server with shared wor

Basic app to show how to login with Facebook, Google, Twitter. Created for learning purpose :) using Xcode 9 and Swift 4.0
Basic app to show how to login with Facebook, Google, Twitter. Created for learning purpose :) using Xcode 9 and Swift 4.0

Social Logins iOS Basic app to show how to login with Facebook, Google, Twitter. Created for learning purpose :) using Xcode 9 and Swift 4.0 Note: Bef

Login-screen-using-Swift - Firebase Apple Open Source Development

Firebase Apple Open Source Development This repository contains all Apple platfo

Login screen using Swift language
Login screen using Swift language

Login Screens Design iOS login Screens, with SwiftUI Designs inspired by Project

Simple Login Screen Project using Swift UI.

Simple Login Screen Simple Login Screen Project using Swift UI. Jump to: Prerequisites: Tutorial uploading XCode project on Github Some Xcode Swift UI

👷‍♀️ login tutorial using Kakao iOS SDK
👷‍♀️ login tutorial using Kakao iOS SDK

KakaoLoginTutorial-iOS 👷‍♀️ login tutorial using Kakao iOS SDK 목차 디자인 가이드 설정단계 애플리케이션 등록 CocoaPods 통해 모듈 설치 Info.plist 설정 초기화 시작하기 전 카카오톡으로 로그인 기본 웹

Custom MacBook login screen and pam modules using multipeer connectivity and usb hardware checks with iOS app for sign in.

Custom MacBook login screen and pam modules using multipeer connectivity and usb hardware checks with iOS app for sign in.

SwiftUI-MSALSample - Sample project to login with MSAL using SwiftUI
SwiftUI-MSALSample - Sample project to login with MSAL using SwiftUI

SwiftUI-MSALSample I could not find a good walkthrough on how to implement MSAL

Owner
Sem de Wilde
Student 
Sem de Wilde
SimpleAuth is designed to do the hard work of social account login on iOS

SimpleAuth is designed to do the hard work of social account login on iOS. It has a small set of public APIs backed by a set of "providers"

Caleb Davenport 1.2k Nov 17, 2022
A simple way to implement Facebook and Google login in your iOS apps.

Simplicity Simplicity is a simple way to implement Facebook and Google login in your iOS apps. Simplicity can be easily extended to support other exte

Simplicity Mobile 681 Dec 18, 2022
SwiftCoreDataLoginPage - Login and registration with core data

Login and Registration Page with CoreData In this basic project, which was used

Buse Köseoğlu 2 Aug 22, 2022
A simple library to make authenticating tvOS apps easy via their iOS counterparts.

Voucher The new Apple TV is amazing but the keyboard input leaves a lot to be desired. Instead of making your users type credentials into their TV, yo

Riz 516 Nov 24, 2022
A simple project for Face ID Authentication for iOS device using LocalAuthentication Framework

BiometricAuthentication This respository is a simple project for Face ID Authentication for iOS device using LocalAuthentication Framework and infoPli

Lee McCormick 0 Oct 23, 2021
Example of simple OAuth2 authentication using Alamofire 5 and RxSwift library

REST Client based on Alamofire 5 and RxSwift library. Supports OAuth2 and Basic authentication interceptor.

Tomáš Smolík 3 Dec 8, 2022
SpotifyLogin is a Swift 5 Framework for authenticating with the Spotify API.

SpotifyLogin SpotifyLogin is a Swift 5 Framework for authenticating with the Spotify API. Usage of this framework is bound under the Developer Terms o

Spotify 343 Dec 8, 2022
Easy to use OAuth 2 library for iOS, written in Swift.

Heimdallr Heimdallr is an OAuth 2.0 client specifically designed for easy usage. It currently supports the resource owner password credentials grant f

trivago N.V. 628 Oct 17, 2022
OAuth2 framework for macOS and iOS, written in Swift.

OAuth2 OAuth2 frameworks for macOS, iOS and tvOS written in Swift 5.0. ⤵️ Installation ?? Usage ?? Sample macOS app (with data loader examples) ?? Tec

Pascal Pfiffner 1.1k Jan 2, 2023
Swift based OAuth library for iOS

OAuthSwift Swift based OAuth library for iOS and macOS. Support OAuth1.0, OAuth2.0 Twitter, Flickr, Github, Instagram, Foursquare, Fitbit, Withings, L

OAuthSwift 3.1k Jan 3, 2023