Skip to content

Commit

Permalink
feature/google-login
Browse files Browse the repository at this point in the history
  • Loading branch information
rohit-zip committed Jun 14, 2024
1 parent 9a549f4 commit eac59ba
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.bloggios.auth.provider.payload.record.RemoteAddressResponse;
import com.bloggios.auth.provider.payload.request.AuthenticationRequest;
import com.bloggios.auth.provider.payload.request.ForgetPasswordRequest;
import com.bloggios.auth.provider.payload.request.GoogleLoginRequest;
import com.bloggios.auth.provider.payload.request.RegisterRequest;
import com.bloggios.auth.provider.payload.response.AuthResponse;
import com.bloggios.auth.provider.payload.response.ModuleResponse;
Expand Down Expand Up @@ -150,11 +151,9 @@ public ResponseEntity<RemoteAddressResponse> remoteAddress(HttpServletRequest re
return ResponseEntity.ok(AsyncUtils.getAsyncResult(authenticationService.remoteAddress(request)));
}

@GetMapping(EndpointConstants.OAuthController.GOOGLE_LOGIN)
public ResponseEntity<AuthResponse> loginGoogle(@RequestHeader("token") String token, @RequestHeader("secret") String secret, HttpServletRequest httpServletRequest) {
log.error("1001 Token Header : {}", httpServletRequest.getHeader("token"));
log.error("1002 Secret Header : {}", httpServletRequest.getHeader("secret"));
CompletableFuture<AuthResponse> authenticate = authenticationService.loginGoogle(token, secret, httpServletRequest);
@PostMapping(EndpointConstants.OAuthController.GOOGLE_LOGIN)
public ResponseEntity<AuthResponse> loginGoogle(@RequestBody GoogleLoginRequest googleLoginRequest, HttpServletRequest httpServletRequest) {
CompletableFuture<AuthResponse> authenticate = authenticationService.loginGoogle(googleLoginRequest, httpServletRequest);
AuthResponse asyncResult = AsyncUtils.getAsyncResult(authenticate);
return ResponseEntity
.ok()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import com.bloggios.auth.provider.payload.record.RemoteAddressResponse;
import com.bloggios.auth.provider.payload.request.AuthenticationRequest;
import com.bloggios.auth.provider.payload.request.ForgetPasswordRequest;
import com.bloggios.auth.provider.payload.request.GoogleLoginRequest;
import com.bloggios.auth.provider.payload.request.RegisterRequest;
import com.bloggios.auth.provider.payload.response.AuthResponse;
import com.bloggios.auth.provider.payload.response.ModuleResponse;
Expand Down Expand Up @@ -447,13 +448,13 @@ public CompletableFuture<RemoteAddressResponse> remoteAddress(HttpServletRequest
}

@Override
public CompletableFuture<AuthResponse> loginGoogle(String token, String secret, HttpServletRequest httpServletRequest) {
public CompletableFuture<AuthResponse> loginGoogle(GoogleLoginRequest googleLoginRequest, HttpServletRequest httpServletRequest) {
long startTime = System.currentTimeMillis();
googleTokenVerifier.authorize(secret);
googleTokenVerifier.authorize(googleLoginRequest.getSecret());
String userInfoEndpoint = "https://openidconnect.googleapis.com/v1/userinfo";
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setBearerAuth(token);
headers.setBearerAuth(googleLoginRequest.getToken());
HttpEntity<String> entity = new HttpEntity<>(headers);
ResponseEntity<Object> response = restTemplate.exchange(
userInfoEndpoint,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright © 2023-2024 Bloggios
* All rights reserved.
* This software is the property of Rohit Parihar and is protected by copyright law.
* The software, including its source code, documentation, and associated files, may not be used, copied, modified, distributed, or sublicensed without the express written consent of Rohit Parihar.
* For licensing and usage inquiries, please contact Rohit Parihar at rohitparih@gmail.com, or you can also contact support@bloggios.com.
* This software is provided as-is, and no warranties or guarantees are made regarding its fitness for any particular purpose or compatibility with any specific technology.
* For license information and terms of use, please refer to the accompanying LICENSE file or visit http://www.apache.org/licenses/LICENSE-2.0.
* Unauthorized use of this software may result in legal action and liability for damages.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.bloggios.auth.provider.payload.request;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.*;

/**
* Owner - Rohit Parihar and Bloggios
* Author - rohit
* Project - auth-provider-application
* Package - com.bloggios.auth.provider.payload.request
* Created_on - June 14 - 2024
* Created_at - 13:23
*/

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@JsonIgnoreProperties(ignoreUnknown = true)
public class GoogleLoginRequest {

private String token;
private String secret;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.bloggios.auth.provider.payload.record.RemoteAddressResponse;
import com.bloggios.auth.provider.payload.request.AuthenticationRequest;
import com.bloggios.auth.provider.payload.request.ForgetPasswordRequest;
import com.bloggios.auth.provider.payload.request.GoogleLoginRequest;
import com.bloggios.auth.provider.payload.request.RegisterRequest;
import com.bloggios.auth.provider.payload.response.AuthResponse;
import com.bloggios.auth.provider.payload.response.ModuleResponse;
Expand Down Expand Up @@ -56,5 +57,5 @@ public interface AuthenticationService {
CompletableFuture<ModuleResponse> forgetPasswordOtp(String email);
CompletableFuture<ModuleResponse> forgetPassword(ForgetPasswordRequest forgetPasswordRequest);
CompletableFuture<RemoteAddressResponse> remoteAddress(HttpServletRequest request);
CompletableFuture<AuthResponse> loginGoogle(String authCode, String secret, HttpServletRequest httpServletRequest);
CompletableFuture<AuthResponse> loginGoogle(GoogleLoginRequest googleLoginRequest, HttpServletRequest httpServletRequest);
}

0 comments on commit eac59ba

Please sign in to comment.