{"id":18667849,"url":"https://github.com/alschmut/msalswiftui","last_synced_at":"2025-06-12T05:07:49.362Z","repository":{"id":184036049,"uuid":"396386482","full_name":"alschmut/MSALSwiftUI","owner":"alschmut","description":"A SwiftUI representation of the official MSAL UIKit Sample app","archived":false,"fork":false,"pushed_at":"2022-01-31T17:22:01.000Z","size":41,"stargazers_count":15,"open_issues_count":1,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-12T00:15:21.903Z","etag":null,"topics":["auth","authentication","authenticator","azure","microsoft","msal","oath","sample","swift","swiftui"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alschmut.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-08-15T14:55:52.000Z","updated_at":"2024-10-02T18:54:22.000Z","dependencies_parsed_at":null,"dependency_job_id":"2ffa06a9-ee40-417a-aec0-a9d8bf69c4e7","html_url":"https://github.com/alschmut/MSALSwiftUI","commit_stats":null,"previous_names":["alschmut/msalswiftui"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/alschmut/MSALSwiftUI","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alschmut%2FMSALSwiftUI","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alschmut%2FMSALSwiftUI/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alschmut%2FMSALSwiftUI/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alschmut%2FMSALSwiftUI/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alschmut","download_url":"https://codeload.github.com/alschmut/MSALSwiftUI/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alschmut%2FMSALSwiftUI/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259402144,"owners_count":22851877,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth","authentication","authenticator","azure","microsoft","msal","oath","sample","swift","swiftui"],"created_at":"2024-11-07T08:40:19.614Z","updated_at":"2025-06-12T05:07:49.353Z","avatar_url":"https://github.com/alschmut.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MSALSwiftUI\n\nThis project intends to give an example of how the MSAL iOS library can be used in a SwiftUI App. \nIt uses the same MSAL APIs but separated from the View. \nThis projects reuses the sample code provided by Microsoft within their MSAL iOS Sample Project:\n\nhttps://github.com/Azure-Samples/ms-identity-mobile-apple-swift-objc\n\n**Important**: I do not guarantee that this project works 100% the same way as the MS Sample does! But I hope it gives some useful input while trying to rewrite the UIKIt sample in SwiftUI :)\n\n\n\n## Use your own Azure App\n\nTo use this project with your own registered Azure App you need to change the following:\n* Project *Bundle Identifier* (`\u003capp_name\u003e` -\u003e `\u003cyour_target\u003e` -\u003e General -\u003e Bundle Identifier)\n* Replace the credentials in `MSAuthCredentials.swift\n  ```swift\n  struct MSAuthCredentials {\n    static let applicationId = \"66855f8a-60cd-445e-a9bb-8cd8eadbd3fa\" // aka clientID\n    static let directoryId = \"common\" // aka tenantID\n  }\n  ```\n\n\n## Overview\nThe [`MSAuthAdapter`](Shared/MSAuthAdapter.swift) contains the business logic for loading the account info silently or with interaction. While the [`MSAuthProxy`](Shared/MSAuthProxy.swift) encapsulates all the MSAL APIs, which mainly stayed the same as in the above mentioned UIKit sample.\n\n```swift\nclass MSAuthState: ObservableObject {\n    @Published var account: Account?\n}\n\nstruct Account: Equatable {\n    let email: String?\n}\n\nstruct AuthView: View {\n    @EnvironmentObject var msAuthState: MSAuthState\n\n    private let msAuthAdapter: MSAuthAdapterProtocol = resolve()\n    \n    var body: some View {\n        VStack(spacing: 40) {\n            Text(msAuthState.account?.email ?? \"Signed out\")\n                .frame(maxWidth: .infinity, alignment: .trailing)\n                .foregroundColor(.gray)\n\n            Button(\"Login with interaction\") {\n                msAuthAdapter.login(withInteraction: true)\n            }\n\n            Button(\"Logout\") {\n                msAuthAdapter.logout()\n            }\n            .disabled(msAuthState.account == nil)\n\n            Button(\"Load device mode\") {\n                msAuthAdapter.loadDeviceMode()\n            }\n            \n            Text(\"See logged console output for more info\")\n                .font(.caption)\n\n            Spacer()\n        }\n        .padding()\n    }\n}\n\n```\n\n\n## Dependencies\n* [Resolver](https://github.com/hmlongco/Resolver) for simple dependency injection\n\n\n## Roadmap\n\nI do not intend to update this project or keep it up to date. \nMicrosoft itself is likely to introduce their own Sample Project for SwiftUI soon (state August 2021).\nSee issue regarding SwiftUI Sample for a similar project https://github.com/Azure-Samples/active-directory-b2c-ios-swift-native-msal/issues/47\n\n\n## Contributing\n\nContributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.\n\n1. Fork the Project\n2. Create your Feature Branch\n3. Commit your Changes\n4. Push to the Branch\n5. Open a Pull Request\n\n\n## License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n\n## Contact\n\nAlexander Schmutz - alexander@t-schmutz.de\n\n\n## Acknowledgements\n* [Resolver](https://github.com/hmlongco/Resolver)\n* [MSAL iOS Sample Code](https://github.com/AzureAD/microsoft-authentication-library-for-objc)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falschmut%2Fmsalswiftui","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falschmut%2Fmsalswiftui","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falschmut%2Fmsalswiftui/lists"}