user2604504
user2604504

Reputation: 717

Github API with iOS

I'm fairly new to iOS development and am particularly new in dealing with REST API's with iOS. I am trying to integrate Github into my app and have been reading through Github's API documentation. I'm having trouble understanding a few concepts and any clarification would be helpful. I know that there are some external libraries (RESTKit etc.) that I could use but I would like to build this app from scratch for learning purposes.

In the Github API documentation the examples keep using curl like so (this is the example online so this is not my token):

curl -i -H 'Authorization: token 5199831f4dd3b79e7c5b7e0ebe75d67aa66e79d4' \
    https://api.github.com/user

How do translate this to an NSURL that I can use for an NSURLRequest?

I'm also a little confused with OAuth2. Github allows for both a web application flow and a non-web application flow. I assume since I'm building an iOS app I would use the non-web application flow. To use the non-web application flow the Github webpage says:

POST /authorizations

Parameters

Name            Type    Description
scopes          array   A list of scopes that this authorization is in.
note            string  Required. A note to remind you what the OAuth token is for.
note_url        string  A URL to remind you what app the OAuth token is for.
client_id       string  The 20 character OAuth app client key for which to create the token.
client_secret   string  The 40 character OAuth app client secret for which to create the token.

I'm confused as to what this means. I already have a client_id and a client_secret but how does this allow me get a new authorization without the users username and password?

I'm sorry if these are very basic questions but I'm very confused and any help would be greatly appreciated.

Upvotes: 3

Views: 1957

Answers (2)

Manish Verma
Manish Verma

Reputation: 539

You can use code from this sample demo app which provides few basic functionalities to interact with GitHub API.

Note*: It provides only few api interactions.

GitHub-Interaction

Hope this helps!!

Upvotes: 1

Thomas Femiani
Thomas Femiani

Reputation: 139

The curl example is adding an HTTP header to the request. The header is not part of the URL, but is part of the data sent to the web server. Here is an existing answer to your question: NSURLRequest setting the HTTP header

Regarding the OAuth2 non-web application flow: In the web-app flow, you send your user to github in their browser, they authenticate directly to github, and are redirected back to your site. You aren't in a browser, so you can't send them to github to enter their credentials. You need to collect their username and password and send them along with your POST to /authorizations using Basic Authentication. I'm sure there is an existing answer for sending a request with basic auth in iOS.

Upvotes: 2

Related Questions