This is a simple example iOS app written in AppAuth and Apollo GraphQL, and demonstrates how to 'Login with CANpass' for an iOS app.
- In the
LoginExamplefolder, run the following command to install the dependencies.
pod install
- Open the
LoginExample.xcworkspaceworkspace.
open LoginExample.xcworkspace
This workspace is configured to include AppAuth and Apollo via CocoaPods.
- Authorization Endpoint
- Token Endpoint
- GraphQL Endpoint
- Client ID
- Redirect URI
- Scopes
let kAuthorizationEndpoint = "https://canpass.me/oauth2/authorize";
let kTokenEndpoint = "https://canpass.me/oauth2/token";
let kGraphQLEndpoint = "https://api.cryptobadge.app/graphql";
let kClientID = "YOUR_CLIENT_ID";
let kRedirectURI = "app.cryptobadge.oauth2:/oauth2redirect/sample-provider";
let kScopes = ["email"]To allow your user to be re-directed back to LoginExample, you’ll needs to associate a custom URL scheme with your app. The schema is everything before the colon (:). In web pages, for example, the scheme is usually http or https. iOS apps can specify their own custom URL schemes. For example, if the redirect URI is app.cryptobadge.oauth2:/oauth2redirect/sample-provider, then the scheme would be app.cryptobadge.oauth2.
Go to the LoginExample\Supporting Files group in Xcode and find Info.plist. Right click on it and choose Open As\Source Code.
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>app.cryptobadge.oauth2</string>
</array>
</dict>
</array>query UserInfo{
me {
id
name
email
path
resourceUrl
}
}
Once you create or update graphql files, the API.swift file will be subsequently updated. You can setup Apollo GraphQL by following this guide https://www.apollographql.com/docs/ios/installation
Our GraphQL service is developing so maybe this schema will out-of-date, so it may be updated manual. (TODO)
apollo-codegen will search for GraphQL code in the Xcode project and generate the Swift types.
npm install -g apollo-codegen
apollo-codegen download-schema http://api.cryptobadge.app/graphql --output schema