title: Oauth2 with swift
body: <p>I'm trying to integrate oauth2 to my project. I have my own api service which written in laravel framework. And I do have oauth2 service as well.</p>
  
  <p>And I have looked some of the tutorials about oauth2 implementation. But I have a question. I have a login function here ;</p>
  
  <pre><code>func login(){
      let url = "http://someurl/oauth/token"
      let paramater: [String : Any] = ["grant_type": "password",
                       "client_id": someid,
                       "client_secret": "somesecret",
                       "username" : "username",
                       "password" : "1234567",
                       "scope" : ""
                       ]
      Alamofire.request(url, method: .post, parameters: paramater, headers: nil).responseJSON { (response) in
          print(response)
          if let dict = response.result.value as? [String:Any]{
              if let accessToken = dict["access_token"] as? String{
                  self.oauth(token: accessToken)
              }
          }
      }
  }
  </code></pre>
  
  <p>I run this function, I take access token and execute this function.</p>
  
  <pre><code>  func oauth(token : String){
      let url = "http://someurl/api/user"
      let header = ["Accept" : "application/json",
                    "Authorization" : "Bearer \(token)"]
      Alamofire.request(url, method: .get, parameters: nil, headers: header).responseJSON { (response) in
          print(response.result.value)
      }
  }
  </code></pre>
  
  <p>With these functions I get the user details. But I'm wondering if I'm doing right. Is it the true way of doing this? If It is not, what is the true way. Thank you.</p>