Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70434

Ionic 4: Access Token

$
0
0

@ebyrock wrote:

Hi,

I am using the following code to get an access token from the back-end server that runs on Azure. But I receive 400 Bad Request error. I am pretty sure I am sending wrong encoded data but don’t know how to fix it. Any help really appreciated.

router.services.ts

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Login } from '../user/Login';
import { puts } from 'util';

const httpOptions = {
  headers: new HttpHeaders().set('Content-Type', 'application/x-www-form-urlencoded')
};
@Injectable({
  providedIn: 'root'
})
export class RouterService {
  [x: string]: any;

  private url = "http://___.azurewebsites.net";

  constructor(private http: HttpClient) { }

  async login(user: Login) {
    return this.postUrl("/token", user);
  }

  async register(user) {
    return this.postUrl("user/create", user);
  }

  private async getUrl(path: string) {
    return new Promise((resolve) => {
      this.http.get(this.url + path).subscribe((data) => {
        console.log(data);
        resolve(data);
      });
    });
  }

  private async postUrl(path: string, post: any) {
    console.log(this.url, path, post);
    return new Promise((resolve) => {
      this.http.post(this.url + path, post).subscribe((data) => {
        resolve(data);
      });
    });
  }

Part of login.page.ts code

export class LoginPage implements OnInit {

  private user: Login = {
    username: '',
    password: '',
    grant_type: "password"
  }

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 70434

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>