Restclient.post Angular 7

Asked

Viewed 38 times

0

I’m trying to create a post like this, more in angular 7:

    get '/callback' do
  # get temporary GitHub code...
  session_code = request.env['rack.request.query_hash']['code']

  # ... and POST it back to GitHub
  result = RestClient.post('https://github.com/login/oauth/access_token',
                          {:client_id => CLIENT_ID,
                           :client_secret => CLIENT_SECRET,
                           :code => session_code},
                           :accept => :json)

  # extract the token and granted scopes
  access_token = JSON.parse(result)['access_token']
end

This way:

getClient(session_code: any) {
    this.http.post("https://github.com/login/oauth/access_token", {
      "client_id": this.CLIENT_ID,
      "client_secret": this.CLIENT_SECRET,
      "code": session_code
    }, httpOptions).subscribe(
      data => {
        console.log("POST Request is successful ", data);
      },
      error => {
        console.log("Error", error);
      }
    );
  }

But this giving errorinserir a descrição da imagem aqui

I’m creating this angular authentication, I found nothing researching: https://developer.github.com/v3/guides/basics-of-authentication/

  • You tried for Postman?

  • No Postman works

  • I think the requisition might be different

  • changed the request to the Postman format, and still gives the same error.

  • give a look at this here https://gist.github.com/jesperorb/6ca596217c8dfba2374966c2b5ab1e. Da uma pesquisada em Cors

  • Shows error details to get a better idea.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.