{ "version": 3, "sources": ["src/app/api-client/http-url-custom-encoder.ts", "projects/mindplay/src/app/core/services/auth.service.ts"], "sourcesContent": ["import { HttpUrlEncodingCodec } from '@angular/common/http';\n\n// https://github.com/angular/angular/issues/11058\nexport default class CustomHttpUrlEncodingCodec extends HttpUrlEncodingCodec {\n encodeKey(key: string): string {\n return encodeURIComponent(key);\n }\n\n encodeValue(value: string): string {\n return encodeURIComponent(value);\n }\n}", "import {inject, Injectable} from '@angular/core';\nimport {HttpClient, HttpContext, HttpHeaders, HttpParams, HttpResponse} from '@angular/common/http';\nimport {map} from 'rxjs/operators';\nimport {Observable} from 'rxjs';\nimport {AuthResponse} from '../models/auth-response';\nimport {ENV_CONFIG} from '../../environment.config';\nimport {SsoProvider} from '../../../../../../src/app/enums/sso-provider.enum';\nimport CustomHttpUrlEncodingCodec from '../../../../../../src/app/api-client/http-url-custom-encoder';\nimport {LsAuthResponse} from '../models/ls-auth-response';\nimport {UserResponseModel} from '../models/user-response-model';\nimport {UserUpdateModel} from '../models/user-update-model';\nimport {NgHttpCachingHeaderModel} from '../ng-http-caching/models/ng-http-caching-header.model';\nimport {TeacherResponseModel} from '../models/teacher-response-model';\n\n@Injectable({\n providedIn: 'root'\n})\nexport class AuthService {\n\n httpClient = inject(HttpClient);\n private environmentConfig = inject(ENV_CONFIG);\n\n constructor() { }\n\n authenticate(\n customerId: number,\n username: string,\n password: string,\n httpContext: HttpContext,\n ngHttpCachingHeaders: NgHttpCachingHeaderModel = null): Observable {\n let headers = new HttpHeaders().append('Content-Type', 'application/json');\n\n if (ngHttpCachingHeaders) {\n headers = Object.keys(ngHttpCachingHeaders)\n .reduce((acc, header) => acc.append(header, ngHttpCachingHeaders[header]), headers)\n }\n\n let requestBody;\n // Set up request\n if (customerId) {\n requestBody = {\n customerId: customerId,\n username: username,\n password: password,\n }\n } else {\n requestBody = {\n username: username,\n password: password,\n }\n }\n\n return this.httpClient.post(`${this.environmentConfig.idsApiUrl}Authenticate`, requestBody, {headers, observe: 'response', context: httpContext}).pipe(\n map((response: HttpResponse) => {\n return response.body as AuthResponse;\n })\n )\n }\n\n authenticateViaSSO(token: string, ssoProvider: SsoProvider): Observable {\n let headers = new HttpHeaders().append('Content-Type', 'application/json')\n\n return this.httpClient.post(`${this.environmentConfig.idsApiUrl}SsoAuthenticate`, {token, ssoProvider}, {headers, observe: 'response'}).pipe(\n map((response: HttpResponse) => {\n return response.body as AuthResponse;\n }),\n )\n }\n\n authenticateLS(token: string, username: string = null, password: string = null, context: HttpContext = null) {\n let headers = new HttpHeaders().append('Content-Type', 'application/X-www-form-urlencoded')\n .append('loginOnly', 'true')\n .append('html', 'true');\n\n if (token) {\n headers = headers.set('IdentityToken', token);\n }\n\n let requestBody = new HttpParams({encoder: new CustomHttpUrlEncodingCodec()})\n .set('grant_type', 'password')\n .set('clientVersion', this.environmentConfig.version)\n\n if (username) {\n requestBody = requestBody.set('username', username);\n }\n\n if (password) {\n requestBody = requestBody.set('password', password);\n }\n\n return this.httpClient.post(`${this.environmentConfig.lsApiUrl}Authenticate`, requestBody, {headers, observe: 'response', context}).pipe(\n map((response: HttpResponse) => {\n return response.body as LsAuthResponse;\n }),\n )\n }\n\n authenticateMP(token: string, timeZoneOffset: number, context: HttpContext = null) {\n let headers = new HttpHeaders()\n .append('Content-Type', 'application/X-www-form-urlencoded')\n .append('Authorization', `Bearer ${token}`)\n .append('timeZoneOffset', `${timeZoneOffset}`);\n\n return this.httpClient.post(`${this.environmentConfig.mpApiUrl}Authenticate`, null, {headers, observe: 'response', context}).pipe(\n map((response: HttpResponse) => {\n return response.body as AuthResponse;\n }),\n );\n }\n\n getUserInfo(token: string) {\n let headers = new HttpHeaders()\n .append('Content-Type', 'application/json')\n .append('Authorization', `bearer ${token}`);\n return this.httpClient.get(`${this.environmentConfig.mpApiUrl}users/Me`, {headers, observe: 'response'}).pipe(\n map((response: HttpResponse) => {\n return response.body as UserResponseModel;\n }),\n )\n }\n\n logoutMPManagerUser(token: string) {\n let headers = new HttpHeaders()\n .append('Content-Type', 'application/json')\n .append('Authorization', `bearer ${token}`);\n return this.httpClient.post(`${this.environmentConfig.mpApiUrl}v1/internal/users/manager/logout`, null, {headers, observe: 'response'}).pipe(\n map((response: HttpResponse) => {\n return response.body;\n }),\n )\n }\n\n forgotPassword(email: string) {\n let headers = new HttpHeaders().append('Content-Type', 'application/json');\n return this.httpClient.post(`${this.environmentConfig.mpApiUrl}v1/internal/users/forgotpassword`, `\"${email}\"`, {headers, observe: 'response'}).pipe(\n map((response: HttpResponse) => {\n return response.body as AuthResponse;\n }),\n )\n }\n\n sendConfirmation(email: string) {\n let headers = new HttpHeaders().append('Content-Type', 'application/json');\n return this.httpClient.post(`${this.environmentConfig.mpApiUrl}v1/internal/users/sendconfirmationemail`, `\"${email}\"`, {headers, observe: 'response'}).pipe(\n map((response: HttpResponse) => {\n return response.body as AuthResponse;\n }),\n )\n }\n\n resetPasswordWithToken(userId: number, newPassword: string, token: string) {\n let headers = new HttpHeaders()\n .append('Content-Type', 'application/json')\n .append('Authorization', `bearer ${token}`);\n return this.httpClient.post(`${this.environmentConfig.mpApiUrl}v1/internal/users/${userId}/resetpassword`, `\"${newPassword}\"`, {headers, observe: 'response'}).pipe(\n map((response: HttpResponse) => {\n return response.body as AuthResponse;\n }),\n )\n }\n\n confirmUserAccountWithToken(userId: number, request: UserUpdateModel, token: string) {\n let headers = new HttpHeaders()\n .append('Content-Type', 'application/json')\n .append('Authorization', `bearer ${token}`);\n return this.httpClient.put(`${this.environmentConfig.mpApiUrl}v1/internal/users/${userId}/confirmaccount`, request, {headers, observe: 'response'}).pipe(\n map((response: HttpResponse) => {\n return response.body as AuthResponse;\n }),\n )\n }\n\n postEulaAccepted(userId: number, token: string) {\n let headers = new HttpHeaders()\n .append('Content-Type', 'application/json')\n .append('Authorization', `bearer ${token}`);\n return this.httpClient.post(`${this.environmentConfig.mpApiUrl}v1/internal/users/eulaaccepted`, `\"${userId}\"`, {headers, observe: 'response'}).pipe(\n map((response: HttpResponse) => {\n return response.body as AuthResponse;\n }),\n )\n }\n\n signupTeacher(email: string, schoolId: number) {\n let headers = new HttpHeaders().append('Content-Type', 'application/json');\n return this.httpClient.post(`${this.environmentConfig.mpApiUrl}v1/internal/teachers/CreateTeacherBySchool?email=${email}&schoolId=${schoolId}`, null, {headers, observe: 'response'}).pipe(\n map((response: HttpResponse) => {\n return response.body as TeacherResponseModel;\n }),\n )\n }\n}\n"], "mappings": ";;;;;;;;;;;;;;;;AAGA,IAAqB,6BAArB,cAAwD,qBAAoB;EACxE,UAAU,KAAW;AACjB,WAAO,mBAAmB,GAAG;EACjC;EAEA,YAAY,OAAa;AACrB,WAAO,mBAAmB,KAAK;EACnC;;;;ACOE,IAAO,eAAP,MAAO,aAAW;EAKtB,cAAA;AAHA,SAAA,aAAa,OAAO,UAAU;AACtB,SAAA,oBAAoB,OAAO,UAAU;EAE7B;EAEhB,aACE,YACA,UACA,UACA,aACA,uBAAiD,MAAI;AACrD,QAAI,UAAU,IAAI,YAAW,EAAG,OAAO,gBAAgB,kBAAkB;AAEzE,QAAI,sBAAsB;AACxB,gBAAU,OAAO,KAAK,oBAAoB,EACvC,OAAO,CAAC,KAAK,WAAW,IAAI,OAAO,QAAQ,qBAAqB,MAAM,CAAC,GAAG,OAAO;IACtF;AAEA,QAAI;AAEJ,QAAI,YAAY;AACd,oBAAc;QACZ;QACA;QACA;;IAEJ,OAAO;AACL,oBAAc;QACZ;QACA;;IAEJ;AAEA,WAAO,KAAK,WAAW,KAAK,GAAG,KAAK,kBAAkB,SAAS,gBAAgB,aAAa,EAAC,SAAS,SAAS,YAAY,SAAS,YAAW,CAAC,EAAE,KAChJ,IAAI,CAAC,aAA+B;AAClC,aAAO,SAAS;IAClB,CAAC,CAAC;EAEN;EAEA,mBAAmB,OAAe,aAAwB;AACxD,QAAI,UAAU,IAAI,YAAW,EAAG,OAAO,gBAAgB,kBAAkB;AAEzE,WAAO,KAAK,WAAW,KAAK,GAAG,KAAK,kBAAkB,SAAS,m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