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 12, 2024
1 parent 6882f66 commit d1d8f4a
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,9 @@ public static class UserController {
public static final String ASSIGN_ROLES = "/assign-roles";
public static final String GET_USER_PROFILE_RESPONSE = "/user-profile-response";
}

public static class OAuthController {
public static final String BASE_PATH = CONTEXT_PATH + "/oauth";
public static final String GOOGLE_LOGIN = "/login-google";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,4 @@ public ResponseEntity<ModuleResponse> forgetPassword(@RequestBody ForgetPassword
public ResponseEntity<RemoteAddressResponse> remoteAddress(HttpServletRequest request) {
return ResponseEntity.ok(AsyncUtils.getAsyncResult(authenticationService.remoteAddress(request)));
}

@GetMapping(EndpointConstants.AuthenticationController.GOOGLE_LOGIN)
public ResponseEntity<AuthResponse> loginGoogle(@RequestParam String token, @RequestParam String secret, HttpServletRequest httpServletRequest) {
CompletableFuture<AuthResponse> authenticate = authenticationService.loginGoogle(token, secret, httpServletRequest);
AuthResponse asyncResult = AsyncUtils.getAsyncResult(authenticate);
return ResponseEntity
.ok()
.header(HttpHeaders.SET_COOKIE, asyncResult.getCookie().toString())
.header(ServiceConstants.COOKIE_TOKEN, asyncResult.getCookieToken())
.body(asyncResult);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* 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.controller;

import com.bloggios.auth.provider.constants.EndpointConstants;
import com.bloggios.auth.provider.constants.ServiceConstants;
import com.bloggios.auth.provider.implementation.AuthenticationServiceImplementation;
import com.bloggios.auth.provider.payload.response.AuthResponse;
import com.bloggios.auth.provider.utils.AsyncUtils;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.util.UriComponentsBuilder;

import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.CompletableFuture;

/**
* Owner - Rohit Parihar and Bloggios
* Author - rohit
* Project - auth-provider-application
* Package - com.bloggios.auth.provider.controller
* Created_on - June 13 - 2024
* Created_at - 00:12
*/

@RestController
@RequestMapping(EndpointConstants.OAuthController.BASE_PATH)
@CrossOrigin("*")
public class OAuthController {

private final AuthenticationServiceImplementation authenticationServiceImplementation;

public OAuthController(AuthenticationServiceImplementation authenticationServiceImplementation) {
this.authenticationServiceImplementation = authenticationServiceImplementation;
}

@GetMapping(EndpointConstants.OAuthController.GOOGLE_LOGIN)
public ResponseEntity<AuthResponse> loginGoogle(@RequestParam String token, @RequestParam String secret, HttpServletRequest httpServletRequest) {
CompletableFuture<AuthResponse> authenticate = authenticationServiceImplementation.loginGoogle(token, secret, httpServletRequest);
AuthResponse asyncResult = AsyncUtils.getAsyncResult(authenticate);
return ResponseEntity
.ok()
.header(HttpHeaders.SET_COOKIE, asyncResult.getCookie().toString())
.header(ServiceConstants.COOKIE_TOKEN, asyncResult.getCookieToken())
.body(asyncResult);
}
}
1 change: 1 addition & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,6 @@ authentication:
path-exclude:
paths:
- /auth-provider/auth/**
- /auth-provider/oauth/**
- /actuator/**
- /oauth2/**

0 comments on commit d1d8f4a

Please sign in to comment.